# Joystick control of two boat motors

Discussion in 'Embedded Systems and Microcontrollers' started by DTB Radio, Sep 29, 2009.

Sep 29, 2009
2
0
I have 2 DC boat (trolling) motors that I want to control using only a pair of PICAXE 08M chips. My current configuration is independent motor control with 1 chip for 1 motor (like a bulldozer or skidloader control scheme for example), each chip reading a single POT to determine direction and speed for its own motor. This system works very nicely, but I want to eliminate the double controls and use a joystick instead. However, I want to implement it with only a pair of PICAXE 08M's (Yes, I know there are better chips for the job, but I want to do it with what I have on hand now, no extra \$\$ layout).

I'm having trouble figuring out exactly how to tackle this challenge. My thought is to have each 08M read both joystick POT's (one POT for speed and forward/reverse control and one for directional control), and from those ADC results, determine the direction and speed of its own motor. Its easy enough to read the ADC's and assign them to variables, then output the interpreted data for each motor, but coming up with the algorithms and code to have each chip interpret that data is giving me a brain fart. I am a complete and total newbie to this area of micro-controlling, I need someone to point me in the right direction here. I don't think I need the full code, just the basic algorithms to manipulate the data. Any help and thoughts would be appreciated.

If I need to give more detail, let me know. Oh, for the mad scientists on the forum, I plan on running the two 12-volt, 50-pound thrust motors from 24 volts just to see how fast I can make a 12-foot jon-boat go on batteries. MUAHAHAHA!!

Sep 29, 2009
2
0
I ended up answering my own question after a couple weeks of hair-pulling. I decided to use the PICAXE 28X2 chip, reading joystick POT's configured for max voltage at full up and full right respectively. Here is the code, working perfectly:

symbol throttle = b0
symbol steering = b1
symbol lmotor = b2
symbol rmotor = b3
symbol lmode = b.0
symbol rmode = b.1

double_speed:
'setfreq m8

main:

allstop:
if throttle > 123 and throttle < 132 and steering > 123 and steering < 132 then
rmotor = 0
lmotor = 0
low rmode
low lmode
goto sendpwm
end if

straight:
if steering > 123 and steering < 132 then
if throttle > 127 then
throttle = throttle - 127
low lmode
low lmode
lmotor = throttle
rmotor = throttle
goto sendpwm
end if
if throttle < 127 then
throttle = 127 - throttle
high lmode
high rmode
lmotor = throttle
rmotor = throttle
goto sendpwm
end if
end if

rotate:
if throttle > 123 and throttle < 132 then
if steering > 127 then
lmotor = steering - 127
rmotor = steering - 127
high rmode
low lmode
goto sendpwm
end if
if steering < 127 then
rmotor = 127 - steering
lmotor = 127 - steering
high lmode
low rmode
end if
end if

rightfwd:
if steering > 127 and throttle > 127 then
steering = steering - 127
throttle = throttle - 127
lmotor = throttle + steering max 127
low lmode
rmotor = throttle - steering
if rmotor > 127 then
rmotor = rmotor - 127
rmotor = 128 - rmotor
high rmode
else
low rmode
end if

goto sendpwm
end if

leftfwd:
if steering < 127 and throttle > 127 then
steering = 127 - steering
throttle = throttle - 127
rmotor = throttle + steering
lmotor = throttle - steering
low rmode
if lmotor > 127 then
lmotor = lmotor - 127
lmotor = 128 - lmotor
high lmode
else
low lmode
end if
goto sendpwm
end if

rightrev:
if steering > 127 and throttle < 127 then
throttle = 127 - throttle
lmotor = steering - throttle
if lmotor > 127 then
lmotor = lmotor - 127
low lmode
else
high lmode
lmotor = 127 - lmotor
end if
rmotor = steering - 127 + throttle max 127
high rmode
goto sendpwm
end if

leftrev:
if steering < 127 and throttle < 127 then
throttle = 127 - throttle
steering = 127 - steering
lmotor = steering + throttle max 127
rmotor = steering - throttle
rmotor = 127 - rmotor
if rmotor > 127 then
high rmode
rmotor = rmotor - 127
else
low rmode
rmotor = 127 - rmotor
end if
high lmode
goto sendpwm
end if

sendpwm:
pwmout c.1, 31, lmotor
pwmout c.2, 31, rmotor
goto main