Kyle1010

01-09-2003, 06:30 PM

We Have A Tank style drive and i would like to know how do i stop our left wheel from going faster than the right by using a codde in the program. Im New so any advice would help thanx in advance

View Full Version : How Do I Program My RC To Spot One wheel From Going faster than the other

Kyle1010

01-09-2003, 06:30 PM

We Have A Tank style drive and i would like to know how do i stop our left wheel from going faster than the right by using a codde in the program. Im New so any advice would help thanx in advance

Noah

01-09-2003, 06:54 PM

You might try something like

if RgtMtr > 127 then LftMtr = LftMtr MAX RgtMtr

' If right motor is forward then limit left motors speed to right motors speed.

if RgtMtr < 127 then LftMtr = LftMtr MIN RgtMtr

' If right motor is reverse then limit left motors speed to right motors speed.

Note: This is PBASIC 2.5. It will not run with the 2.0 stamp programmer.

If you need help understanding this, PM me.

if RgtMtr > 127 then LftMtr = LftMtr MAX RgtMtr

' If right motor is forward then limit left motors speed to right motors speed.

if RgtMtr < 127 then LftMtr = LftMtr MIN RgtMtr

' If right motor is reverse then limit left motors speed to right motors speed.

Note: This is PBASIC 2.5. It will not run with the 2.0 stamp programmer.

If you need help understanding this, PM me.

Jeff McCune

01-11-2003, 03:37 PM

Unfortunately, motors aren't perfect nor identical. I assume you're having a problem along the lines of, "I drive both motors at 254, but the left side is moving faster."

This can be solved by using some constants at the top of your code and calibrating your drive train through experimentation. Try using the USER MODE on the OI to display the value being sent to one of the motors, and then tweak it until both sides are spinning the same. Then, take that offset and incorporate it into your drive subroutine.

This can be solved by using some constants at the top of your code and calibrating your drive train through experimentation. Try using the USER MODE on the OI to display the value being sent to one of the motors, and then tweak it until both sides are spinning the same. Then, take that offset and incorporate it into your drive subroutine.

Kai Zhao

01-12-2003, 01:45 PM

This is a cut and paste job from our code last year. Thanks to Joe Johnson for giving us parts of the following code in New York two years ago when our drive system was horrible.

Just as a note, all of the numbers are in hexadecimal and shifting by X = dividing by 2^x. If you have no idea what I'm talking about, email me (or reply) and I'll explain. Sorry for the really obfuscated code, you'll probably want some free time to analyze it fully.

Alan's Highly Scalable/Complex Speed Balancer -- (MESSAGE FROM ALAN: I don't understand either ) If you are not him, here is my (Kai's) explanation.

First we must seperate the code into three easy to digest portions '"((abs(PWM1-$80)" gets us the distance we are trying to travel from neutral, the answer will be signed then we multiply that answer by "(13 + (3 * ((PWM1 - $80)) >> 15 )) >> 4 )". If we are going forward, we get a zero from "(3 * ((PWM1 - $80)) >> 15 )", if we are going reverse, we get a 3.

The number we get out of that (0 or 3) is added to 13 which is then multiplied to the desired speed (NOT velocity).

After multiplying by either 13 or 16, we shift by 4 which is effectively dividing by 16. Therefore, we lower (by 13/16) the speed is the motor is going forward and keep it the same if we are going in reverse.

The last step of "* (1 - ((PWM1 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE" allows us add direction into speed and make it work.

We are using this equation as the example: "PWM1 = ((abs (PWM1 - $80) * (13 + (3 * ((PWM1 - $80)) >> 15 )) >> 4 ) * (1 - ((PWM1 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE"

If we need to change the ratio, we need to find denominator which is a power of 2. Now we need the numerator and we need to find the difference between the numerator and denominator.

([numerator] + ([numerator - denominator] * ((PWM1 - $80)) >> 15 )) >> [denominator who is a integer power of 2 (ex. 2,4,8,16,32,64,etc)] )

PWM1 = (((abs (PWM1 - $80) * (13 + (3 * ((PWM1 - $80) >> 15)))) >> 4 ) * (1 - ((PWM1 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE

PWM2 = (((abs (PWM2 - $80) * (13 + (3 * ((PWM2 - $80) >> 15)))) >> 4 ) * (1 - ((PWM2 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE

-Kai Zhao

Just as a note, all of the numbers are in hexadecimal and shifting by X = dividing by 2^x. If you have no idea what I'm talking about, email me (or reply) and I'll explain. Sorry for the really obfuscated code, you'll probably want some free time to analyze it fully.

Alan's Highly Scalable/Complex Speed Balancer -- (MESSAGE FROM ALAN: I don't understand either ) If you are not him, here is my (Kai's) explanation.

First we must seperate the code into three easy to digest portions '"((abs(PWM1-$80)" gets us the distance we are trying to travel from neutral, the answer will be signed then we multiply that answer by "(13 + (3 * ((PWM1 - $80)) >> 15 )) >> 4 )". If we are going forward, we get a zero from "(3 * ((PWM1 - $80)) >> 15 )", if we are going reverse, we get a 3.

The number we get out of that (0 or 3) is added to 13 which is then multiplied to the desired speed (NOT velocity).

After multiplying by either 13 or 16, we shift by 4 which is effectively dividing by 16. Therefore, we lower (by 13/16) the speed is the motor is going forward and keep it the same if we are going in reverse.

The last step of "* (1 - ((PWM1 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE" allows us add direction into speed and make it work.

We are using this equation as the example: "PWM1 = ((abs (PWM1 - $80) * (13 + (3 * ((PWM1 - $80)) >> 15 )) >> 4 ) * (1 - ((PWM1 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE"

If we need to change the ratio, we need to find denominator which is a power of 2. Now we need the numerator and we need to find the difference between the numerator and denominator.

([numerator] + ([numerator - denominator] * ((PWM1 - $80)) >> 15 )) >> [denominator who is a integer power of 2 (ex. 2,4,8,16,32,64,etc)] )

PWM1 = (((abs (PWM1 - $80) * (13 + (3 * ((PWM1 - $80) >> 15)))) >> 4 ) * (1 - ((PWM1 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE

PWM2 = (((abs (PWM2 - $80) * (13 + (3 * ((PWM2 - $80) >> 15)))) >> 4 ) * (1 - ((PWM2 - $80) >> 15 << 1)) + $80) MIN $24 MAX $DE

-Kai Zhao

Mwilber

01-12-2003, 02:40 PM

If you haven't already load up dashboard and make sure your joysticks are callibrated correctly then duct tape those dials in place. This same thing happened to us and we spent a few hours trying to program around it and found out that with the dashboard it tells you the numerical value of the location of your joystick (.i.e it would display it at 127/127 when in the middle)

Bduggan04

01-12-2003, 03:30 PM

Originally posted by Mwilber

If you haven't already load up dashboard and make sure your joysticks are callibrated correctly then duct tape those dials in place. This same thing happened to us and we spent a few hours trying to program around it and found out that with the dashboard it tells you the numerical value of the location of your joystick (.i.e it would display it at 127/127 when in the middle)

You can also use the indicators on the OI to show when the joysticks are zeroed (at 127). This lets you quickly adjust it while the robot is disabled.

Also, you could use the yaw rate sensor (gyro) to correct the robot's path if it isn't going straight.

If you haven't already load up dashboard and make sure your joysticks are callibrated correctly then duct tape those dials in place. This same thing happened to us and we spent a few hours trying to program around it and found out that with the dashboard it tells you the numerical value of the location of your joystick (.i.e it would display it at 127/127 when in the middle)

You can also use the indicators on the OI to show when the joysticks are zeroed (at 127). This lets you quickly adjust it while the robot is disabled.

Also, you could use the yaw rate sensor (gyro) to correct the robot's path if it isn't going straight.

vBulletin® v3.6.4, Copyright ©2000-2014, Jelsoft Enterprises Ltd.