Raspberry Pi Robotic Arm Project2


Presentation Description

Presentation to Southend Linux User Group June 2014.


Presentation Transcript

Raspberry Pi Robotic Arm Project:

Mark Turner Raspberry Pi Robotic Arm Project Warning – A video camera will be used in this demonstration. I will be capturing audience images onto the Raspberry Pi, but they will be deleted at the end of the demonstration.

My Computers:

My Computers

PowerPoint Presentation:

My Computers

PowerPoint Presentation:

My Computers Where is the hard drive? Where is the case? Where is the keyboard / mouse and other ‘normal’ stuff?

PowerPoint Presentation:

My Idea + =

PowerPoint Presentation:

Then I thought I could add video, and make it available on the internet with wheels on it, then make it fully autonomous…… My Idea

Hardware Description:

Hardware Description

PowerPoint Presentation:

The first task was to get the Raspberry Pi working . I chose Raspbian Wheezy OS installed from the NOOBS installation. The advantage of Raspbian from NOOBS is that it provides all the options to run using SSH (that is log in from a remote PC) and enables you to expand the SD card to its full capacity. Next I wanted it to connect by wifi . I brought a mini wifi adaptor from Amazon for £5. It worked straight away. Next I set the RPi up with a static IP address. This is necessary so that I always know which IP address to use when logging in. (Guidance for this can be found on the internet) First Stage – Setting up the ‘wireless’

PowerPoint Presentation:

Switch to Rpi and log in using Putty and WinSCP First Stage – Setting up the ‘wireless’ Demo

Second Stage – Driving the arm:

The first challenge I faced was to obtain drivers to control the arm. Fortunately I found a great article in ‘ Magpi ’ issue number 2 which was using the exact same arm that I had. They pointed me in the right direction of the necessary driver ( pyusb-1.0.0-a1 ). Second Stage – Driving the arm I recommend looking at the MagPi website for some really interesting article: www.themagpi.com This issue of MagPi also provided me with some simple Python code to test the arm.

Driving the arm:

The arm is activated by sending commands which correspond to the individual motors or the led: 0,1,0 - Rotate Base Anti-clockwise 0,2,0 - Rotate Base Clockwise 64,0,0 - Shoulder Down 128,0,0 - Shoulder Up 16,0,0 - Elbow Up 32,0,0 - Elbow Down 4,0,0 - Wrist Up 8,0,0 - Wrist Down 2,0,0 - Grip Open 1,0,0 - Grip Close 0,0,1 - Light On 0,0,0 – Light Off Driving the arm

Driving the arm in Python Demo:

Driving the arm in Python Demo Switch to Rpi in Putty Change directory: CD /home/pi/arm Run the script: python arm.py

Hardware Description:

Hardware Description

PowerPoint Presentation:

Some research indicated that if I wanted to use the Raspberry Pi on my network, I would need to configure it as a server. After some trial and error, I configured Apache2, thanks to the many good videos I found on YouTube. Third Stage – Setting RPi as a Server Next I created a simple page on my server as test.php to confirm all was working NOTE: It is vital to set the correct permissions for web user access when configuring the server. (This took me ages to figure out).

PowerPoint Presentation:

Third Stage – Setting RPi as a Server Demo Switch to Firefox Open test.php

Fourth Stage– Scripting:

Fourth Stage– Scripting To send a command to the arm, first I use the ‘Post’ function in HTML to send a call to a PHP script. The PHP script then calls a specific Python script corresponding to the HTML request. In order to run a Python script from the HTML web page, it is necessary to call a php page located in the cgi -bin folder. The php can then call Python using the ‘exec’ command.

1st HTML Page:

1 st HTML Page <td>< form action=" run_gripopen.php " method="POST" > <input type="hidden" name="variable" value="100" /> <input type="image" src ="Pob-Grip.jpg" align=" center " HEIGHT=50 WIDTH=50 BORDER=1name="submit" /> <p align=" center ">Grip Open<p/p> </form></td> Here is an snippet of my HTML script to open the gripper. Note the form action=“ run_gripopen.php ” is calling the php script with the “Post” method.

1st HTML Page Demo:

1 st HTML Page Demo Switch to Firefox Open

Script Diagram of 1st Attempt:

Script Diagram of 1 st Attempt In my first experiments I used a separate PHP script for each movement of the arm. This then called an individual arm movement Python script. This meant I had 12 PHP and 12 Python scripts.

Arm Script 1st Attempt:

Arm Script 1 st Attempt This is an example of one of those PHP scripts. This one calls the Python script to move the arm base anticlockwise. <? php exec( " python2 cgi-bin/baseanti.py &" ); header("Location: index3G.html"); exit; ?>

Scripting Evolution:

Scripting Evolution To cut down the number of PHP and Python scripts to run, I sent values to a single Python script via a single PHP script. The value corresponded to a required arm movement, and was read using an ‘if / elif ‘ statement. In addition, I modified the HTML so that I could also send a ‘duration’ value to the arm.

Scripting Evolution - HTML:

Scripting Evolution - HTML <td><form action=" cgi -bin/run_duration3G.php" method =“Get"> <input type="hidden" name=" action " value=" 3 " /> <input type="text" name=" duration " style="width: 50px;" /> <input type="image" src ="lightbulb.jpg" align=" center " HEIGHT=50 WIDTH=50 BORDER=1name="submit" /> <p align=" center ">Light On - 3<p/p> </form></td> This snippet of my HTML script asks for a duration in the text box. I send this as ‘Duration’ and the ‘Action’ value ‘3’ to the PHP script.

Scripting Evolution - PHP:

Scripting Evolution - PHP <? php $id1 = $_GET[' duration ']; $id2 = $_GET[' action ']; exec ( " sudo python /home/pi/arm/command.py $id1 $id2" ); $ gohere = ""; header("Location: $ gohere "); exit ; ?> The ‘Duration’ value is assigned to $id1 (the first argument), and the ‘Action’ value is assigned to $id2 (the second argument). These are added to the Python command line and the values sent to Python.

Scripting Evolution - Python:

Scripting Evolution - Python #Create a variable for duration xString = sys.argv [1] Duration = int ( xString ) #Create a variable for command code yString = sys.argv [2] Code = int ( yString ) #Move arm anti if code is 1 if Code==1: ArmCmd =[2,0,0] elif Code==2: ArmCmd =[1,0,0] elif Code==3: ArmCmd =[0,0,1] ……. Here is an snippet of my Python script. It reads the first and second arguments sent with the initiation code, and uses an if / elif statement to determine which arm movement to perform. It also uses the duration argument to determine how long the arm moves for (not shown).

Scripting Evolution Demo:

Scripting Evolution Demo Switch to Firefox Open

Hardware Description:

Hardware Description

Fifth Stage – Video Feed:

Fifth Stage – Video Feed To make the video feed work I installed ‘Motion’ software onto the Rpi . I followed a number of YouTube tutorials in order to get the video camera working – there was a lot of trial and error. In order for the video to ‘transmit’ on the network it is necessary to set the correct TCP/IP port in the ‘ m otion.conf ’ file. Mine is set to ‘ control_port 8080’.

PowerPoint Presentation:

Motion will capture a frame every time there is a movement. It can be used as a surveillance system. Note: It can save a lot of images in a short time, so be careful you do not fill up your RPi memory with lots of pictures! Fifth Stage – Video Feed The HTML page is configured to ‘look’ for this transmission: < center ><IMG SRC="" HEIGHT=240 WIDTH=320 BORDER=1></ center > With motion running (which is started by the command ‘motion –n’ on the RPi ), log onto the web page and the video should appear. NOTE: Internet Explorer does not work with the video feed. I recommend Firefox or Chrome.

Video On & Off:

Video On & Off As I wanted the browser to control all aspects of the project, I decided to add the ability to turn the video feed on and off as well. Again, this uses a PHP script. This time the PHP only uses a command line execution: <? php exec( " sudo motion -n " ); $ gohere = ""; header(" Location : $ gohere "); exit ; ?> I had a problem as the HTML does not refresh the page once the video camera is turned on. So I added a dummy ‘video on’ button which forces the page to refresh, enabling the video feed. To turn the video off, I call a similar PHP script with the following change: exec ( " sudo service motion stop" );

PowerPoint Presentation:

Switch to Firefox Open Fifth Stage – Video Feed Demo

Next Steps:

Next Steps I have several more ideas I want to explore with this project: Number 1: Multiple Arm Movements At the moment I can only send one command at a time from the HTML. However, it is possible to combine commands so that more than one motor is activated. This is achieved by sending the combined codes. For example: 0,2,0 - Rotate Base Clockwise 64,0,0 - Shoulder Up This can be sent as 64,2,0 Demo: Switch to Putty and run python arm2.py

Next Steps:

Next Steps Number 2: Programmable Arm. I would like to be able to provide a series of commands to the arm, and then run them in sequence. Number 3: Feed back on the position of the arm. This can be achieved using a potentiometer for the base. For the Shoulder, Elbow and Wrist I want to use accelerometers. These are very small, and can be made wireless. For the gripper I want to add a Hall Effect sensor. With feedback, I should be able to send a ‘reset’ command, and the arm will move back to a baseline position.

Next Steps:

Next Steps Number 4: Active Vision The most ambitious step would be to make the arm move in response to changes in the field of view. This should be achievable using ‘ OpenCV ’ software Number 5: Motorised Base I have a dream that the arm can be put onto wheels, and it can drive around, either under control from the web interface, or autonomously. I have started experiments with wheeled robot control with the RPi and an Arduino with motor shield.

Thank you for listening. Any questions?:

Thank you for listening. Any questions?

authorStream Live Help