Let's Make Robots!

Airship differential steering troubles

Hi all,

I'm faced with a problem - some friends and I are building a semi-autonomous airship (only a little one) and I've been given the electronics and programming to do, but I'm having trouble getting the pwm commands to work properly.

I'm using a little joystick with 2 pots to control it, the y-direction one controls the overall speed and direction of both motors and the x-direction one puts a left/right bias on them to turn the thing.

Here's the bit of test code I've got with just the one pot being used


symbol zero1 = b1

symbol zero2 = b2

symbol value1 = b3

symbol value2 = b4

symbol diff1 = b5

symbol diff2 = b6

symbol offset1 = b7

symbol offset2 = b8


readADC 1,zero1

readADC 2,zero2


readADC 1,value1

readADC 2,value2

if value1 > zero1 then

diff1 = value1 - zero1

offset1 = diff1 * 16 / 10

hpwm 0,0,%0001,96,offset1

hpwm 0,0,%0100,96,offset1

elseif value1 <= zero1 then

diff1 = zero1 - value1

offset1 = diff1 * 16 /10

hpwm 0,0,%0010,96,offset1

hpwm 0,0,%1000,96,offset1


goto main


The binary strings in the hpwm commands correspond to the direction of each motor (0001 is A forward, 0100 is B forward, 0010 is A back and 1000 is B back)

My problem is that when both motors are controlled by the one command (0101, 1001 etc) everything works fine, but when they are separated like this, one motor goes a lot faster than it should and the other barely moves, it's the same in both directions.

The faster motor corresponds to the 00xx binary position.

I'm stumped, can anyone help?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Now I got it --I didn't know what chip you were using. Yes, the 18x would be better --I think it has 2 proper PWM outs. You might have to go up to the 28x, I dunno, check the pinouts.

The joystick at a 45 simply feels funny. It is very hard to push it in a straight line to the corner. With those little play station joysticks, the sensitivity is so much that it just adds to the "pushing it straight to the corner" problem. It turns out twitchy and sloppy in my opinion. Converting the joystick with math is better but is a little funny with picaxe. The fact that bytes overflow and that picaxe does not do negitive numbers, it can be a little tricky but it will work and works quite well after everything gets dialed in.


You say airship and differential drive. I am assuming you have something like a blimp with a motor and propeller on each side. If a motor throttles up on one side, say the left, the airship would turn right. I will also assume that you don't intend to run the motors in reverse. That being said, here is my thought:

Get rid of the HPWM stuff. The HPWM picaxe stuff has baffled almost everyone who has tried it. Not a single person here at LMR has ever figured it out. Seriously. I would say, with just the two motors, I would go with pwmout and pwmduty instead. These are much easier and simpler commands, have been used by almost everyone, and should simplify your problems quite a bit. In addition, I, in the past, have needed to convert the X/Y of a joystick to differential drive. This can be done with some math or by simply turning your joystick to a 45 degree angle. Either way has it's issues, but I have done them both and know how to get them working. If this turns out to be any part of your problem (it was for me) just give me a shout. I am happy to help.

That's nearly what I've got (well, what I will have when it gets built)

Actually we're having a motor/propellor on each side but running them both ways, and a mini servo in there somewhere to tilt them from 90deg down through 90deg up to get vertical motion.

Just after I posted I found something by oddbot about the 45 deg joystick, I like the idea :)

HPWM has baffled me completely too! Is there a way of using a 20X2 or an 18M2 (those are the axes I've got lying around) to get independent speed control of 2 motors simultaneously? I think the 18 has two pwm lines, so maybe using one of those and 2 I/Os for each motor...

Either that or use 2 processors, but I don't really want to do that.

What issues did you have with the 45deg joystick?