Autonomous Robotic Arm (python)

Description
Learn how to program a robotic arm to operate autonomously using Python in Pictoblox. This activity guides you through initializing the robotic arm, writing movement and gripper actions, and using a continuous loop for independent operation. You’ll also explore the transition from stage mode to upload mode, allowing the robotic arm to function without an external system or Pictoblox connection. Ideal for robotics enthusiasts and learners, this guide will help you take full control of robotic arms in a simple, efficient way.

Introduction

In this activity, we will how we can program a robotic arm to work independently without human interference or external system requirements. for this activity we will be writing the code in python environment of pictoblox. So, Let’s get started.

Let’s Code

  1. Open Pictoblox and choose the python as coding environment.
  2. Go to the boards tab and select.
  3. Quarky boards will be imported into the script area by default. firstly we need to initlize the robotic arm and setting related to the robot. follow the script given below.

sprite = Sprite(‘Tobi’)
quarky=Quarky()
roboticArm = RoboticArm(1,2,3,4)
roboticArm.setgripperangle(90,145)
roboticArm.sethome()
import time

4. Now create a forever loop and define all the sets and movements inside the loop.  as shown below.

while True:
roboticArm.gripperaction(“open”)
roboticArm.movexyzonebyone(0,200,15,1000)
roboticArm.gotoinoneaxis(180,”Y”,1000)
roboticArm.gripperaction(“close”)
roboticArm.gotoinoneaxis(150,”X”,1000)
roboticArm.gripperaction(“open”)
roboticArm.sethome()
roboticArm.gripperaction(“close”)
time.sleep(1)
roboticArm.gripperaction(“open”)
roboticArm.movexyzonebyone(-60,160,10,1000)
roboticArm.gotoinoneaxis(200,”Y”,1000)
roboticArm.gotoinoneaxis(15,”Z”,1000)
roboticArm.gripperaction(“close”)
roboticArm.gotoinoneaxis(150,”X”,1000)
roboticArm.gripperaction(“open”)
roboticArm.sethome()
roboticArm.gripperaction(“close”)
time.sleep(0.2)
Note: you can change these steps based on the requirements.

Complete Script

 

sprite = Sprite(‘Tobi’)
quarky=Quarky()
roboticArm = RoboticArm(1,2,3,4)
roboticArm.setgripperangle(90,145)
roboticArm.sethome()
import time
while True:
roboticArm.gripperaction(“open”)
roboticArm.movexyzonebyone(0,200,15,1000)
roboticArm.gotoinoneaxis(180,”Y”,1000)
roboticArm.gripperaction(“close”)
roboticArm.gotoinoneaxis(150,”X”,1000)
roboticArm.gripperaction(“open”)
roboticArm.sethome()
roboticArm.gripperaction(“close”)
time.sleep(1)
roboticArm.gripperaction(“open”)
roboticArm.movexyzonebyone(-60,160,10,1000)
roboticArm.gotoinoneaxis(200,”Y”,1000)
roboticArm.gotoinoneaxis(15,”Z”,1000)
roboticArm.gripperaction(“close”)
roboticArm.gotoinoneaxis(150,”X”,1000)
roboticArm.gripperaction(“open”)
roboticArm.sethome()
roboticArm.gripperaction(“close”)
time.sleep(0.2)
This script for stage mode where the robotic arm and the pictoblox need to remain connected. As long as they are connected, the arm will work according to the script, but if the connection gets disconnected, the arm will stop working and you have to connect again. There is one another approach by which you can make it work completely independently.

Python Script for Upload Mode

1. Change the work code from stage mode to upload mode. create the below script.

from quarky import *
from expansion_addon import RoboticArm
import time
roboticArm = RoboticArm(1,2,3,4)
roboticArm.setgripperangle(90,145)
roboticArm.sethome()
while True:
roboticArm.gripperaction(“open”)
roboticArm.movexyzonebyone(0,200,15,1000)
roboticArm.gotoinoneaxis(180,”Y”,1000)
roboticArm.gripperaction(“close”)
roboticArm.gotoinoneaxis(150,”X”,1000)
roboticArm.gripperaction(“open”)
roboticArm.sethome()
roboticArm.gripperaction(“close”)
time.sleep(1)
roboticArm.gripperaction(“open”)
roboticArm.movexyzonebyone(-60,160,10,1000)
roboticArm.gotoinoneaxis(200,”Y”,1000)
roboticArm.gotoinoneaxis(15,”Z”,1000)
roboticArm.gripperaction(“close”)
roboticArm.gotoinoneaxis(150,”X”,1000)
roboticArm.gripperaction(“open”)
roboticArm.sethome()
roboticArm.gripperaction(“close”)
time.sleep(0.2)

2. connect your quarky via USB and upload the code twice.  by doing this , you  have uploaded the code into the quarky memory and there is no need for  any system or pictoblox to remain connected. now quarky can run independently

Table of Contents