ROBOTC.net forums
http://www.robotc.net/forums/

encoders and synchronizing motors
http://www.robotc.net/forums/viewtopic.php?f=52&t=3245
Page 1 of 1

Author:  swhite [ Thu Apr 28, 2011 10:35 pm ]
Post subject:  encoders and synchronizing motors

Working on an FTC robot for competition tomorrow and would like to find some way to synch our drive motors together. We are thinking about using the encoders but have no idea how to do that using robotc. Any help will be greatly appreciated.

Author:  MHTS [ Fri Apr 29, 2011 1:13 am ]
Post subject:  Re: encoders and synchronizing motors

Are you trying to make the robot to go straight? If so try the following. Basically, the difference of the left and right encoder values becomes your correction factor. The bigger the difference the bigger the correction (i.e. Proportional PID control). The difference is multiplied to a proportional scale factor (Kp). You need to fine tune this value to make the correction smooth. Then you apply the calculated correction to the left and right motors. If the encoders are running with the same values, the difference is zero. Then no correction will happen. If the right wheel runs faster, you will have a positive correction that will make the left motor turn faster and the right motor turn slower and vice versa.
Code:
#define BOUND(n, l, h)  (((n) < (l))? (l): ((n) > (h))? (h): (n))
#define Kp              0.1     //you may need to tune this

void Drive(int drivePower)
{
    int turnPower = nMotorEncoder[rightMotor] - nMotorEncoder[leftMotor];
    turnPower = BOUND((int)(turnPower*Kp), -10, 10);
    motor[leftMotor] = BOUND(drivePower + turnPower, -100, 100);
    motor[rightMotor] = BOUNT(drivePower - turnPower, -100, 100);
}

task main()
{
    nMotorEncoder[leftMotor] = 0;
    nMotorEncoder[rightMotor] = 0;
    while (true)
    {
        Drive(50);
        wait1Msec(10);
    }
}

Author:  swhite [ Sat Apr 30, 2011 11:29 am ]
Post subject:  Re: encoders and synchronizing motors

thank you very much. That is basically what we are trying to do... We have been having difficulty getting the robot to go straight in autonomous mode so this will definitely help. The code we are using in autonomous mode requires the robot to turn so I am assuming that I will have to add this block as needed. Please correct me if I am wrong. My programming skills are lacking and its kind of like the blind leading the blind...

Author:  MHTS [ Sat Apr 30, 2011 11:32 am ]
Post subject:  Re: encoders and synchronizing motors

If you want to do other things in autonomous, please refer to this discussion thread.
viewtopic.php?f=52&t=3152

Author:  hongyeus [ Fri Oct 21, 2011 11:21 pm ]
Post subject:  Re: encoders and synchronizing motors

One question I have is that if we are going to four wheel drive a robot, would it be necessary to put encoders on each wheel?
Thanks.

Author:  magicode [ Fri Oct 21, 2011 11:40 pm ]
Post subject:  Re: encoders and synchronizing motors

While it is hard to speak without knowing the specifics of your drive, if it is a 4 wheel tank drive, then generally no. You would only really need one encoder on either side of the robot.

Author:  MHTS [ Sat Oct 22, 2011 1:49 am ]
Post subject:  Re: encoders and synchronizing motors

hongyeus wrote:
One question I have is that if we are going to four wheel drive a robot, would it be necessary to put encoders on each wheel?
Thanks.

Are you talking about 4-wheel drive or 4-motor drive? Most of the time, people have 4-wheel drive but only one motor for each side. The two wheels on each side are usually chained to the same motor. So typically, you have one encoder on each side. If you truly have 4-motor drive, then the question is: are the two motors on one side synchronized by a chain? If so, you still need only one encoder for each side. If you don't have a mechanism to synchronize the wheels on one side, you may have a problem. In that case, you may need one encoder for each motor just for synchronizing the speed. Normally, there is no benefit of 2 unsynchronized motors on one side unless you have a mecanum drive train. Mecanum allows your robot to go sideway. In that case, you also need 4 encoders, one on each wheel so you can calculate the net movement of the robot.

Author:  magicode [ Sat Oct 22, 2011 9:24 am ]
Post subject:  Re: encoders and synchronizing motors

Quote:
Normally, there is no benefit of 2 unsynchronized motors on one side unless you have a mecanum drive train

I would disagree with this statement. Many teams use this configuration to gain more speed and pushing power. Having the motors unsychronized does not have too much of in effect in driver control mode (except if your robot is experiencing a lot of slippage). And I have been able to program fairly accurate PID control using only two encoders on a 4 motor tank drive.

Author:  MHTS [ Sat Oct 22, 2011 9:44 am ]
Post subject:  Re: encoders and synchronizing motors

You can still use 4 motors for the 4 wheels to gain speed but using a chain to link them will make sure the two wheels on one side is always running the same speed. You could run them independently but then you will have to put encoders on the two wheels of the same side and use software to monitor their speeds to make sure they are in sync. I am not saying it's not doable with just two encoders for 4 motors but I personally don't see benefits of doing that.

Author:  magicode [ Sat Oct 22, 2011 11:04 am ]
Post subject:  Re: encoders and synchronizing motors

You're right, that chaining the two motored wheels together on each side is in general a better idea then leaving them independent. I'm just saying that if chaining is not an option (some teams either don't have room, or find that it over complicates their chassis to chain the wheels), and only two encoders are available, then good results can be achieved with just two encoders on unchained wheels.

Author:  hongyeus [ Sat Oct 22, 2011 12:22 pm ]
Post subject:  Re: encoders and synchronizing motors

All right, thanks so much, and yes sorry I was referring to 4-motor tank drive. I will see if I can chain the motors on each side together.

Thanks!

Author:  hongyeus [ Sat Oct 22, 2011 3:21 pm ]
Post subject:  Re: encoders and synchronizing motors

I actually have another question about chaining the two motors on each side together... If the two motors chained together did run at different powers, wouldn't this in effect increase the resistance and literally "force" the motors to run together? Would there be any negative impacts of doing this?

Author:  MHTS [ Sat Oct 22, 2011 4:50 pm ]
Post subject:  Re: encoders and synchronizing motors

First, when you chain 2 motors together, make sure your code will program the same power to them. So then the speed difference should be minimal if any. The motors can take that stress produced by the difference. To the motor, this is just a slight variant in its loading. It is equivalent to a weight difference on all the four wheels or even different friction on the wheels, then one of the motors will work slightly harder than the other one. So this is normal stress. Even if you don't chain them together, assuming the wheels don't slip, you will have the same effect (one wheel running faster and takes more load).

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/