Mckenzie river driftboat, fly angler and rower - SD21

PatBig

Member
Hello, I am an experienced model boats builder but totally new to picaxe and writing code. I have built a 1/6 scale McKenzie river driftboat, a typical craft for the Pacific Northwest rivers, with a fly angler and the bow and a guy rowing on the back seat. I am a fly angler myself and lived in Oregon, so it's a walk on memory lane. The fly angler should turn right or left, and cast. The rower should move the boat in all directions. I am using a SD21 aka AXE031 servo board. Three RC channel will control the boat: joystick up and down, right and left for the rower, and a three positions switch for the fly angler. So far after many attempts I seem to be getting closer to getting the rower to row. I still have problems with servos not always starting or resting at the same position, which can create excess tension on the linkages, and difficulties synchronizing the servos. This is the code I have written so far, just for the rower. It's moving all four servos, though I haven not yet connected them to the oars. I'd be very grateful for feedback or advice on how to make it better, my comfort zone is clearly more with hand tools.
23340

The code:

Symbol servo1 = 63 'servo 1 base register
Symbol Servo1p = 84 'Servo 1 positive offset register
Symbol Servo1n = 105 'servo1 negative offset register
Symbol Servo2 = 64 'servo 2 base register
Symbol Servo2p = 85 'Servo 2 positive offset register
Symbol Servo2n = 106 'servo2 negative offset register
symbol servo3 = 65
symbol servo3p = 86
symbol servo3n = 107
symbol servo4 = 66
symbol servo4p = 87
symbol servo4n = 108
symbol Speed = 50 'medium slow speed
symbol base = 200
symbol Offset = 120 '+/-50 from center position

w0 = 0
w1 = 0


ProgStart:
i2cslave $c2,i2cslow, i2cbyte 'setup i2c port for servo controller
writei2c servo1, (base)
i2cslave $c2,i2cslow, i2cbyte 'setup i2c port for servo controller
writei2c servo2, (base)
i2cslave $c2,i2cslow, i2cbyte 'setup i2c port for servo controller
writei2c servo3, (base)
i2cslave $c2,i2cslow, i2cbyte 'setup i2c port for servo controller
writei2c servo4, (base)
hi2cout 126,(90) ;memorize power up position
hi2cout 0, (speed)
hi2cout 3, (speed)
hi2cout 6, (speed)
hi2cout 9, (speed)

MainLoop:

hi2cout servo1,(base) ; center position to start loop
hi2cout servo2, (base)
hi2cout servo3, (base)
hi2cout servo4, (base)
pulsin C.6,1,w0 ;go forward
if w0 > 165 then
goto Avtoute
Endif
if w0 < 135 then ;reverse
goto Artoute
Endif
pulsin C.7,1,w1 ;left turn
if w1 > 165 then
goto Virgauche
endif
if w1 < 135 then ;right turn
goto Virdroite
endif
Goto Mainloop

Avtoute: ;all servos synchronize to row forward

hi2cout servo1n,(offset)
hi2cout servo3n,(offset)
Pause 500
hi2cout servo2p, (offset)
hi2cout servo4p, (offset)
pause 500
hi2cout servo1p, (offset)
hi2cout servo3p, (offset)
pause 500
hi2cout servo2n, (offset)
hi2cout servo4n, (offset)
pause 500
Goto Mainloop

Artoute: ;all servos synchronize to row backwards

hi2cout servo1n,(Offset)
Pause 2000
hi2cout servo2p, (Offset)
pause 2000
hi2cout servo1p, (offset)
pause 2000
hi2cout servo2n, (offset)
pause 2000
Goto Mainloop

Virgauche: ;servos 1 and 2 row, 3 and 4 rest, boat turns left

hi2cout servo1n,(offset)
hi2cout servo3,(base)
hi2cout servo4, (base)
Pause 1000
hi2cout servo2p, (offset)
pause 1000
hi2cout servo1p, (offset)
pause 1000
hi2cout servo2n, (offset)
pause 1000
Goto mainloop


Virdroite: ;servos 3 and 4 row, servos 1 and 2 rest, boat turns right

hi2cout servo1,(base)
hi2cout servo2, (base)
hi2cout servo3n, (offset)
Pause 1000
hi2cout servo4p, (Offset)
pause 1000
hi2cout servo3p, (offset)
pause 1000
hi2cout servo4n, (offset)
pause 1000
Goto mainloop
 

lbenson

Senior Member
Beautiful work there, and a very ambitious project. Welcome to the forum.

I'm not familiar with the AXE031 and its controls, but I see nothing intrinsically wrong with your code. You may have to be more explicit about what is going wrong, and perhaps include a video.

(My wife says, "I wants one" (when the bugs are worked out)). Here is her boat-building project--a 10-foot sailing dingy:
23341
 
Last edited:
Top