View unanswered posts | View active topics It is currently Wed Oct 21, 2020 12:50 am

Reply to topic  [ 2 posts ] 
Robot TC synchronize 4 dc motors with quad. encoders+arduino 
Author Message

Joined: Thu Feb 07, 2013 6:53 pm
Posts: 1
Post Robot TC synchronize 4 dc motors with quad. encoders+arduino
Hi Guys,
I'm tryng to have 4 dc motors connected to 4 quadrature encoders to move at the same exact speed where one of the motors is the main one and the other are following and correcting the position
to "catch" the first one.
Let's say we have a rectangle made in Plywood and I'm connecting the 4 corners with 4 steelcables going to a pulley the motors+quadrant encoders.
I want to memorize(where possible) the first position and then from there move the rectangle up and down in a parallel position from the original position memorized.
I'm attaching a video to show you the project as it is now, the 4 motors are running but the encoders are not showing me the same numbers=not the same position and speed.
Let's say I have a 4 wheeled robot and I want it to move straight, is the same thing I'm tryng to do with my rectangle goin up and down keeping it parallel.
I just downloaded the RobotC software and any help guy will be so greatly appreciated about an eventual code.

Thanks everyone! :D


File comment: Video showing the project working with Arduino, the debug window is showing the wrong numbers from the encoders, this arduino scketch by the way is not trying to adjust the motors is just moving it and this is why I need help..!

[ Play Quicktime file ] IMG_2243.MOV [ 3.73 MiB | Viewed 16715 times ]
Thu Feb 07, 2013 7:43 pm
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Robot TC synchronize 4 dc motors with quad. encoders+ard
The tricky part may be setting up and reading the encoder values, depending on how they work exactly. Once they are set up, though, you can use something similar to an autostraighten program (short example below) to 'synchronize' the motors together:

task main() //Assume encoderA is the 'master' motor, and you want to synch the other motors to it.
   int speedB;

   while(true)      //Creates an infinite loop, since "true" always evaluates to true
      if(SensorValue[encoderB] == SensorValue[encoderA])//If the encoder values are equal
         motor[motorB] = speedB; //Maintain speed      

      else if(SensorValue[encoderB] > SensorValue[encoderA])//If encoderB is greater than encoderA (moving faster)
         speedB = speedB - 1; //slow it down

      else if(SensorValue[encoderB] < SensorValue[encoderA])//If encoderB is less than encoderA (moving slower)
         speedB = speedB + 1; //speed it up
         motor[motorB] = speedB;

You would have to repeat the process for the encoders/speeds of the other two motors as well. Also, you may want to put in an 'acceptable range', for instance, if the encoder counts are within 1 count of each other; this will prevent the motor speed from 'flip-flopping between a value that is 1 higher or 1 less than the desired encoder count. It's a bit tricky to do, but you definitely have the right idea.

I would focus on setting up the encoders in ROBOTC and normalizing their values first, then using them to control the motor speeds. We have done some testing with programming a mechanical encoder you may want to look into as well. Keep us updated on the progress of this project!

Edit: Looking through this again, I did make an error with the previous code:


Needs to be outside of the infinite while loop; otherwise, it will reset speedB to 50 everything the loop executes (which is quite often, in the matter of milliseconds).

Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.

Fri Feb 08, 2013 5:54 pm
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.