This demo shows how to control the Snapper robot arm using joysticks for input in backhoe mode. Backhoe means that each of the servos are being controlled by an individual analog input - one joystick axis for the base, one joystick axis for the shoulder, etc. There are no inverse kinematics being used - inverse kinematics are discussed in another demo.
This demonstration used the same firmware as some of the other more complex control methods - the control mode is changed in a simple line of code that we will show you.
Project Parts List:
The RobotGeek Snapper Robot Arm Kit comes with all of the robotic hardware you need for this demo including the analog inputs.
This project can also be done with the RobotGeek Snapper Core Arm kit, assuming that you have your own microcontroller, power supply and wiring. You will also need 1 static analog input (like a knob or a slider) and 2 or 3 self centering joysticks.
Arm Placement and Setup:
Whenever you program the Snapper arm, you should first manually position the servos in the sleep configuration. This will make the transition from off to on for the arm smoother.
When working with the arm, we recommend that you weigh it down / secure it to the surface you are working on. This will stop the arm from falling over due to sudden movements on startup. Make sure there is plenty of room around the arm so that it will not hit anything.
If you're arm shows movement during programming, you can remove the shield or remover the power jumpers during programming.
The arm should never be powered by USB alone. Always connect the DC power before you connect in the USB cable, and disconnect the USB cable before you disconnect the power. If you want to power down the arm but leave the USB plugged in, remove the power jumpers.
Durign operation, if your arm contorts, collides or otherwise curls in on itself, remove power and usb immediately.
It's normal to hear a buzzing noise coming from one or more of the servos during operation.
Note that if you have the original 9G Mini Servo Gripper, you should follow the original wiring diagram. The only difference is that you will attach the 9g servo to pin 10 instead of attaching a RobotGeek Servo
|Device||Sensor Shield Port|
Upload the Firmware
Open The Code
The rest of this guide assumes that you've set up the required libraries and sketches in the Snapper Arm Getting Started Guide and the Geekduino Getting Started Guide. These guides will help you to install and setup the Tools and Libraries and Snapper Sketches
Open the Arduino IDE and navigate to the following sketch:
File -> Sketchbook -> RobotGeek Sketches ->
Setting Gripper Type
Before you can load the code onto your Robot Arm, you'll need to adjust your code to match your gripper type. Around line 67 you should see the following code block
//#define GRIPPER_TYPE ROBOT_GEEK_9G_GRIPPER //#define GRIPPER_TYPE ROBOT_GEEK_PARALLEL_GRIPPER
If you have any problems finding these lines, just press the 'compile' button and you'll see an error just below the code block.
In the code block, the two lines are Commented Out. Any line that starts with
// is not processed by the Arduino IDE. This is useful for making code comments or to de-activate code without deleting the line. You will need to Uncomment one line by removing the slashes as shown below.
If you are using the RobotGeek Parallel Gripper, uncomment the second line. Your code should look like
//#define GRIPPER_TYPE ROBOT_GEEK_9G_GRIPPER #define GRIPPER_TYPE ROBOT_GEEK_PARALLEL_GRIPPER
If you are using the RobotGeek 9G Gripper, uncomment the first line. Your code should look like
#define GRIPPER_TYPE ROBOT_GEEK_9G_GRIPPER //#define GRIPPER_TYPE ROBOT_GEEK_PARALLEL_GRIPPER
Now that the gripper type is defined, the code will take care of correctly processing your gripper type.
Setting Control Mode
By default, this firmware will start in backhoe control mode. This is defined at line 86.
#define DEFAULT_CONTROL_MODE IKM_BACKHOE //#define DEFAULT_CONTROL_MODE IKM_IK3D_CARTESIAN //#define DEFAULT_CONTROL_MODE IKM_CYLINDRICAL
Similarly to how we chose a gripper, we can choose a control mode. Other guides will show you how to use Cartesian and Cylindrical control mode. In this guide we will leave the code as is and use the arm in backhoe mode.
Compiling / Upload
Click the 'Verify' button . If you get any errors, make sure you've setup the RobotGeek Tools and Libraries in the Geekduino Getting Started Guide. If everything worked out then you should see a 'Done Compiling' message under the code.
Now click the Upload button to load the code onto your microcontroller.Once the firmware is uploaded, the Snapper Arm will move to a 'home' position - each joint servo will center, causing the arm to make an 'L' pose.
Each joint of the snapper arm can be controlled by a separate joystick. Moving the joystick to the left/right or up/down will adjust move the servo in that direction. When the joystick is centered at its home position, the servo will stay in its current position. Adjusting the rotational knob will absolutely adjust the gripper: that is the position of the knob corresponds to the position of the gripper servo.
Be mindful of how tight you close the gripper on objects, especially if you are using the older 9g gripper. It is possible to burn the 9g Micro Servo out by closing too tightly on rigid objects. Even on the parallel gripper, you do not want to stress the servo unnecessarily.
Before you can program your own sequences, you'll need to read the current servo values for various arm poses. This can be accomplished by connecting the arm to the serial monitor in the Arduino IDE.
Make sure your microcontroller is connected to your PC and that you have the correct serial port chosen from the
Tools->Serial Port menu. Now click the magnifying glass in the upper right corner. This will open the Arduino Serial Monitor in a separate window. The Serial Monitor allows you to communicate wit the sketch
Every time you open/close the serial monitor, the Geekduino will reset. You can disable this behavior by setting the Geekduino's
RST (reset) switch to
M for manual reset. Just remember to set the switch back to
AUTO before you program your board again. For the rest of this guide however, leave the
RST switch set to
The Serial Monitor should have the following default settings:
- No line ending
- 9600 baud
The snapper arm should now show the following text
Starting RobotGeek Analog IK Demo Analog Control Mode Active. Control Mode:Backhoe / Joint Control Mode Send '1' or press the 'Capture' pushbutton to pause the joysticks and capture the current pose.
Use the joysticks to move the snapper arm to a position you would like to capture. Once you are at that position, press the 'Capture' pushbutton attached to digital pin 2, or enter
1 into the serial monitor and hit
Send. This will pause the joystick control engine and output the current servo positions to the screen. You should see a code block that looks like the following (the actual values will vary)
Exiting Analog IK Control Mode. Current Arm Coordinate Values: Base Servo: 1500 Shoulder Servo: 1069 Elbow Servo 1638 Wrist Servo: 843 Gripper: 2400 Sequence Control Code g_bIKMode = IKM_BACKHOE; IKSequencingControl(1500, 1069, 1638, 843, 0, 2400,2000,1000, 1);
The first several lines list out the current positions of the arm. The last two are the lines you are going to need to write your sequence.
First is the line
g_bIKMode = IKM_BACKHOE;
This line only needs to be present in your code once at the beginning of the sequence. This line lets the Snapper Arm know that the sequence will be in Backhoe mode. Copy this line into a Text editor or a new Arduino Sketch for later.
The second line,
IKSequencingControl(1500, 1069, 1638, 843, 0, 2400,2000,1000, 1);
contains all of the data for each servo in one line of code. This line will later be put back into the sketch. For now, just copy this line to a text editor for later.
Once you have copied this value down, you can hit the 'Capture' pushbutton again to start the joystick control engine. Now move the arm to your next desired pose, and repeat the capture process. We recommend that you start with 5 different poses and move onto the next step before you start creating longer pose sequences.
The poses displayed to the serial monitor are the servo positional values currently being sent to the arm servos. The current amount of load the arm is carrying may effect the actual position of the arm in real-space.
Custom Pose Playback
Now that you have your custom poses, you can go to the Snapper Arm Playback guide to see how to put your poses into a standalone firmware.
PC Control These demos and projects allow the robot to be controlled via a computer.
ArbotiX Commander Control - These demos and projects control the Robot using the ArbotiX Commander, the handheld Arduino based remote control.
Direct Control - These demos and projects control the Robot directly from sensors connected directly to the Robot's control board.
Pose Control - These demos and projects allow you to create and playback a sequence of poses.
Serial Control - These demos and projects control the robot using a serial packet protocol.
Standalone - These demos and projects are deisgned to let your robot function without a computer or additional microcontroller.
Wireless Control - These demos and projects allow you to control the robot wirelessly - usually by replacing the Serial Connection with XBee modules.
Reference - These articles have technical details regarding the control and operation of the robot.
More info here