Page 1 of 1

Raspberry Pi Camera Robot Modification

PostPosted: Mon Nov 16, 2015 4:55 pm
by adamrobots
Im in the process of building a R Pi Camera robot. Im considering adding a servo controlled claw at the front to pick up and move things while its out exploring. How easy would it be to add code to control one more servo. I would be looking at adding an extra joystick to the web interface to open and close the claw. Can you give me a heads up on all the files i would need to edit in order to implement this. Im having a read through the source files on bit bucket and im getting and understanding but want to make sure i dont miss anything. Any help and advise would be greatly appreciated...

Many thanks
adamrobots :mrgreen:

Re: Raspberry Pi Camera Robot Modification

PostPosted: Tue Nov 17, 2015 7:50 pm
by Alan
Hi there,

Welcome to the forums. :)

You will probably need to modify a number of files to get this working, but there are a couple of different approaches which will affect that precise number needed.

First off, do you think that perhaps you could get away with disabling one of the neck servos and using the connector for the claw servo instead? The pan servo for example (you can always turn the robot if you want to look left or right). If you were ok to do this then you could get away with just modifying the web interface.

Anyway, the first file to modify would be the web interface index.html. If you're changing the function of the pan servo then I'd suggest providing seperate sliders for the tilt servo, and the claw (pan) servo and using the command

socket.send( "SetNeckAngles " + clawAngle + " " + tiltAngle );

whenever one changes.

Otherwise, if you're adding an extra servo, you'd need to define an extra command, something like SetClawAngle and use it like this

socket.send( "SetClawAngle " + clawAngle );

Moving onto the Python code, you'd first need to modify robot_web_server.py to handle the SetClawAngle command. See line 184 for how the SetNeckAngle command is handled.

At this point, you're faced with a choice. If you can attach the signal line of the servo motor to one of the Pi GPIO pins, you can write Python code in robot_web_server.py to set the claw angle, using code similar to that given in this tutorial.

If on the otherhand you'd like to attach the servo to the mini driver, you still have a way to go... Basically you'd need to follow the path of a command like robot.setNeckAngles( panAngle, tiltAngle ) (line 200 of robot_web_server.py) into robot_controller.py, then into mini_driver.py before the angle is sent over USB to the mini_driver_firmware.ino sketch, at this point you'd need to receive the angle and modify the update loop of the sketch to output the claw angle.

So hopefully that gives you some ideas on how you can approach this. My advice would be to try the simple method of co-opting the pan servo first and then maybe move onto one of the more involved approaches if you want a bit more control. If there's any further information you need, please let me know.

Regards

Alan