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

Motor Sync
http://robotc.net/forums/viewtopic.php?f=11&t=3044
Page 1 of 1

Author:  Shazam1973 [ Fri Feb 18, 2011 7:58 pm ]
Post subject:  Motor Sync

I teach a high school robotics class and I'm just geting started using ROBOTC with the Cortex controller. I used ROBOTC with Lego NXT before this and we were able to synchronize the motors. The code looked something like this:
Code:
nSyncedMotors = synchBC;
nSyncedTurnRatio = 100;

Does ROBOTC support motor syncing for Cortex? If so, how?

I did search the forum for this and found nothing so hopefully this is not a repost.

Author:  RoboDesigners [ Fri Feb 18, 2011 11:38 pm ]
Post subject:  Re: Motor Sync

I do not think so... (I don't have Cortex, but I haven't seen it for PIC)

If you just want to make it easier/quicker to run two motors at once (disregarding PID syncing), insert a function like this just before task main():

Code:
void drive(int power)
{
  motor[leftmotor] = power;
  motor[rightmotor] = power;
}


Then you can just call it by typing:
Code:
drive(90); //Drives forward at power level 90

Author:  jbflot [ Sat Feb 19, 2011 8:51 am ]
Post subject:  Re: Motor Sync

Unfortunately, since the encoders aren't built into the motors (like the NXT motors are), things like synching aren't possible. If what you're trying to do is have the robot drive straight, there way to compare one encoder value to another, and have the robot self-correct its movement. In ROBOTC, if you go to File - Open Sample Program - Shaft Encoders - Moving Straight.c, you'll find the following code:

Code:
#pragma config(Sensor, dgtl1,  rightEncoder,        sensorQuadEncoder)
#pragma config(Sensor, dgtl3,  leftEncoder,         sensorQuadEncoder)
#pragma config(Motor,  port2,           rightMotor,    tmotorNormal, openLoop, reversed)
#pragma config(Motor,  port3,           leftMotor,     tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/*----------------------------------------------------------------------------------------------------*\
|*                                 - Moving Straight with Encoders -                                  *|
|*                                      ROBOTC on VEX 2.0 CORTEX                                      *|
|*                                                                                                    *|
|*  This program implements a self-straightening algorithm that provides a higher power level to the  *|
|*  motor that has traveled less, determined by comparing the values of the two encoders.             *|
|*  There is a 2 second pause at the beginning of the program.                                        *|
|*                                                                                                    *|
|*                                        ROBOT CONFIGURATION                                         *|
|*    NOTES:                                                                                          *|
|*    1)  Reversing 'rightMotor' (port 2) in the "Motors and Sensors Setup" is needed with the        *|
|*        "Squarebot" model, but may not be needed for all robot configurations.                      *|
|*    2)  Whichever encoder is being used for feedback should be cleared just before it starts        *|
|*        counting by using the "SensorValue(encoder) = 0;".  This helps ensure consistancy.          *|
|*                                                                                                    *|
|*    MOTORS & SENSORS:                                                                               *|
|*    [I/O Port]          [Name]              [Type]                [Description]                     *|
|*    Motor   - Port 2    rightMotor          VEX 3-wire module     Right side motor                  *|
|*    Motor   - Port 3    leftMotor           VEX 3-wire module     Left side motor                   *|
|*    Digital - Port 1,2  rightEncoder        VEX Shaft Encoder     Right side                        *|
|*    Digital - Port 3,4  leftEncoder         VEX Shaft Encoder     Left side                         *|
\*----------------------------------------------------------------------------------------------------*/


//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main()
{
    wait1Msec(2000);                            // Robot waits for 2000 milliseconds before executing program

    SensorValue[rightEncoder] = 0;    // Set the encoder so that it starts counting at 0
    SensorValue[leftEncoder]  = 0;    // Set the encoder so that it starts counting at 0

    while(1 == 1)        // Creates an infinite loop, since "true" always evaluates to true
    {
        if(SensorValue[rightEncoder] == SensorValue[leftEncoder]) // If rightEncoder has counted the same amount as leftEncoder:
        {
            // Move Forward
            motor[rightMotor] = 80;        // Right Motor is run at power level 80
            motor[leftMotor]  = 80;        // Left Motor is run at power level 80
        }
        else if(SensorValue[rightEncoder] > SensorValue[leftEncoder])    // If rightEncoder has counted more encoder counts
        {
            // Turn slightly right
            motor[rightMotor] = 60;        // Right Motor is run at power level 60
            motor[leftMotor]  = 80;        // Left Motor is run at power level 80
        }
        else    // Only runs if leftEncoder has counted more encoder counts
        {
            // Turn slightly left
            motor[rightMotor] = 80;        // Right Motor is run at power level 80
            motor[leftMotor]  = 60;        // Left Motor is run at power level 60
        }
    }

}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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