The easiest way to control the Robot Turret is via the included joystick. This page will show you how to wire your joystick to your ArbotiX robocontroller and what code to load onto the ArbotiX Robocontroller.
This code for this demo project will read the analog value from the joysticks, convert the raw value into a value ready for the DYNAMIXEL servos, and then write the positions to the servos. The code will also impose angle limits on the pan/tilt system and offer variable speed, adjustable by the user.
The vertical joystick will control the tilt servo while the horizontal joystick will control the pan servo. These motions can be swapped in code, or by physically swapping out the 2 sensors. This code can work with a wide variety of joysticks. It can also work with other analog sensors, though some code modifications may be necessary depending on the desired behavior.
Project Parts List:
|Analog 0||Joystick (Horizontal)|
|Analog 1||Joystick (Vertical)|
|DYNAMIXEL Bus||DYNAMIXEL Chain|
|DC Jack||SMPS Power Supply, Battery, or other 11-12v power|
Load the PhantomX Joystick Demo Code onto the ArbotiX-M Robocontroller. You will need to plug in your FTDI cable / programming device to program the robocontroller, but you can remove it after programming the robocontroller.
If you have problems loading your code onto your ArbotiX-M, see the ArbotiX Getting Started Guide
TILT_LOWER_LIMITdefine limits (in servo position) that the tilt servo will not go beyond. These values are tuned so that the tilt servo's bracket will not hit the servo. You may wish to adjust these values depending on what you have mounted to the turret.
PAN_LOWER_LIMITlimit the pan servo's motion. By default the pan servo is given a full range of motion (300°/0-1023) but again, you may wish to adjust this to suit your needs.
- This code limits the servos' motion by controling the variables that are sent to the servos. It is also possible to set the clockwise(AX_CW_ANGLE_LIMIT_L) and counter-clockwise (AX_CCW_ANGLE_LIMIT_L) limits for each individual servo. Keep in mind that these limits are set in EEPROM and will stay in place until you set new limits
ax12SetRegister2(AX_CW_ANGLE_LIMIT_L, value); ax12SetRegister2(AX_CCW_ANGLE_LIMIT_L, value);where
valueis a number between 0 and 1023 corresponding to the position of the servo.
By changing the
speedvariable, you can adjust the overall speed of the turret. A higher value will cause the turret to move faster, while a lower value will cause it to move slower. Values from 5-500 work the best.
It is also possible to set the goal speed for each individual servo. This value is stored in RAM and will be reset when the servo loses power.
valueis a number between 0 and 1023. At '0' the motor will go as fast as possible with no speed control. 1-1023 will increase the speed of the servo linearaly (each unit increases the RPM by ~.111 rpm)
DEFAULT_TILTset the default position of the turret. When the arbotix is powered on, the turret will slowly move to this position.
DEADBANDHIGHdefine a low and high limits for the joystick to be centered within. The ideal joystick centers at '512' but many fall outside of this value. If you experience 'drifting' where the servos slowly move without your input, you may need to adjust these values.