Analog Joystick Control for the ScorpionX Robot Turret
Description
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
Wiring
The servos pictured below will look slighly different than the ones in your kit. The wiring for the servos is the same as shown in the assembly guide for your turret.

Pin | Device |
---|---|
Analog 0 | Joystick (Horizontal) |
Analog 1 | Joystick (Vertical) |
DYNAMIXEL Bus | DYNAMIXEL Chain |
DC Jack | SMPS Power Supply, Battery, or other 11-14v power |
Download Code
Download Joystick Turret Code for ArbotiX Robocontroller
Load the MX 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
Code Notes
TILT_UPPER_LIMIT
andTILT_LOWER_LIMIT
define 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.- Similarly
PAN_UPPER_LIMIT
andPAN_LOWER_LIMIT
limit 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);
wherevalue
is a number between 0 and 1023 corresponding to the position of the servo. -
By changing the
speed
variable, 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.
ax12SetRegister2(AX_GOAL_SPEED_L, value);
Wherevalue
is 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_PAN
andDEFAULT_TILT
set the default position of the turret. When the arbotix is powered on, the turret will slowly move to this position.DEADBANDLOW
andDEADBANDHIGH
define 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.
Code

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