In the last demo you learned how to control each individual servo on the Snapper Arm. In this demo you will harness the power of Inverse Kinematics to move the servos in tandem to reach a specific point in space.
For example, let's say you want to move the gripper on the Snapper Arm directly down along the Z-Axis. To do this you would need to move the shoulder, elbow and wrist servos to specific positions until the gripper moved directly down relative to it's original position - a tedious process. Inverse Kinematics (or IK) uses a series of kinematic equations to determine the position for each joint so that the gripper (or 'end effector') will move to a specific position in X/Y/Z space. Using IK, you an issue a single X/Y/Z position you would like the arm to move to, instead of manually moving each joint on the arm.
SnapperArmJoystickControl firmware contains a fully functional IK engine. You do not need to be able to write or understand the kinematic equations in order to use the firmware (though it is a great place to start when you want to learn about the inner workings of kinematics)
You can use the
SnapperArmJoystickControl firmware to set the X/Y/Z position of the arm using the joystick control panel, and to read the current IK position to load into a playback firmware.
Project Parts List:
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.You will need to comment out the first line and uncomment the second. Your code should look like this:
//#define DEFAULT_CONTROL_MODE IKM_BACKHOE #define DEFAULT_CONTROL_MODE IKM_IK3D_CARTESIAN //#define DEFAULT_CONTROL_MODE IKM_CYLINDRICAL
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.
When you press the Upload button , the Arduino IDE will always first verify/compile the code, to you don't need to manually hit 'verify' every time. We have done so here to make sure that our code and libraries are working before proceeding.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 x/y/z coordinate 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 coordinate in that direction. When the joystick is centered at its home position, the coordinate 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:Cartesian IK 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.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: X Axis: 0.00 Y Axis: 82.61 Z Axis: 224.52 Wrist Angle: 0 Gripper: 1631 Sequence Control Code g_bIKMode = IKM_IK3D_CARTESIAN; IKSequencingControl(0.00, 82.61, 224.52, 0.00, 0, 1631,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_IK3D_CARTESIAN;
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(0.00, 82.61, 224.52, 0.00, 0, 1631,2000,1000, 1);
contains all of the data for each position 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