Track robot for beginners
Track robots are very grateful for beginners thanks to it navigation simplicity. But one will soon face the problem how to combine joystick controll values into motor movement directions. Few weeks ago I tried to teach my sons how to make functional robots.
I chose the most general track robot available. Tamiya parts are very fancy for beginners. Lets say nothing special is on this robot. What I want to share with beginners is the code. It is not easy to combine values from joystick into PWM commands for motors. Also due to fact that mechanical center of joystick does not match with electrical center.
Joystick is from toy controll remote.
REM Picaxe 28X1 with PWM module - controlls two motors
init:
symbol direct = b5 REM direction of motors movement - bits
symbol right = b3 REM right track movement
symbol left = b4 REM left track movement
symbol rig = b6 REM right track slowdown
symbol le = b7 REM left track slowdown
symbol opc0 = b8 REM value of second half of joystick way forward-back
symbol opc1 = b9 REM value of second half of joystick way left-right
symbol centr0 = 125 REM center position value of joystick forward-back
symbol centr1 = 128 REM center position value of joystick left-right
let opc0 = 255 - centr0 REM value of second half of joystick way forward-back
let opc1 = 255 - centr1 REM value of second half of joystick way left-right
pwmout 1,63,0 REM left track motor
pwmout 2,63,0 REM right track motor
main:
gosub readjoy REM read joystick values
gosub direction REM calculate speed for both motors
gosub ahead REM send direction to motors
debug
pause 100
goto main
readjoy:
readadc 0,b1 REM forward-back
readadc 1,b2 REM left-right
return
direction: REM motors speed calculation
if b1 = centr0 then REM joystick speed at center position
let direct = %00000000
let right=0
let left = 0
endif
if b1 <centr0 then REM joystick speed backwards
let direct = %00000101
let right = 255 - b1 - opc0 * 255 / centr0 max 255
let left = 255 - b1 - opc0 * 255 / centr0 max 255
endif
if b1 >centr0 then REM joystick speed forwards
let direct = %00001010
let right = b1 - centr0 * 255 / opc0 max 255
let left = b1 - centr0 * 255 / opc0 max 255
endif
if b2 = centr1 then REM joystick direction center
let rig= 0
let le = 0
endif
if b2 <centr1 then REM joystick direction left
let rig= 0
let le = b2 * 255 / centr1
let le = 255 - le max left
endif
if b2 >centr1 then REM joystick direction right
let le = 0
let rig= b2 - centr1 * 255 / opc1 max right
endif
let left = left - le REM combine speed and slowdown for left track
let right= right- rig REM combine speed and slowdown for left track
return
ahead: REM send command to motors
let outpins = direct REM directions for both motors
pwmout 1,63,left
pwmout 2,63,right
return
rides based in joystick controll commands
- Actuators / output devices: 2x tamiya gears at 1:65 ratio
- Control method: nanual controll
- CPU: Pic 28x1
- Operating system: Picaxe
- Power source: 3x 1, 5V AA lithium cells
- Programming language: Basic
- Sensors / input devices: no sensors, bi-directional analog joystick
- Target environment: indoor