Software > Software

Skid Steering (Differential Thrust) on a boat calculations

(1/1)

**grimsy**:

The usual starter line, if Im not in the right place let me know but heres the story:

Ive got a model boat wired up with a raspberry pi(Experimenting with python I'm aware there's better options haha), wired up to two regular DC motors. Now I feel like I'm missing something simple here, probably just blind from staring at the thing too much, but I cant figure out how to calculate the differential steering at all. I'm completely clueless. admittedly calculations arent my strong suit, this is just a hobby for me.

So basically, I have an initial thrust value of 0-100 and a steering value of -1 to 1. -1 on steering being left. Reversing will come later, first I gotta move at all :D

So what I've got to figure out is what the right motor PWM and left PWM is for any given value of the two variables.

As I said, its a hobby, I may be doing something stupid or ridiculous here so let me know, I'm beginning to doubt if python really is the best choice and I'm thinking of migrating over to c++. Either way though if anyone can give some advice or even just point me in the right direction to figure out the problem it would be very much appreciated.

**bdk6**:

I'm not sure exactly what you are asking for, but maybe this will help. If I'm not on track, let me know. I may be able to clarify some things.

To restate the problem, you want the boat to move forward and possibly turn left or right some amount, based on an input variable from -1 (left) to 0 (straight) to +1 (right).

There are many ways to approach it. This is one.

To move straight ahead both motors should turn the same speed. Let's start with 50%

To turn left, the RIGHT motor should turn faster than the left. Since there will be more resistance, let's keep the left motor the same speed and turn the right one faster to minimize speed change.

To turn right, the LEFT motor should go faster, similar to above.

Let's write some pseudocode to set two variables to the desired PWM percentage.

leftMotorSpeed = 50; // First set both to 50%

rightMotorSpeed = 50;

differentialSpeed = turnVariable * 50; // differential speed will be somewhere between -50 (for -1) and +50 (for +1)

// Now add the differential to the appropriate motor

if turnVariable < 0

rightMotorSpeed = rightMotorSpeed + abs(differentialSpeed) // add the absolute value since the differential is negative

if turnVariable > 0

leftMotorSpeed = leftMotorSpeed + abs(differentialSpeed) // doesn't really need the abs() but I like to program defensively

// if it is not greater than 0 or less than 0 then it is 0 and doesn't need to be added

Now you can convert those motor speed percentages to whatever values you need and send them to the motors.

Does this help?

Navigation

[0] Message Index

Go to full version