View unanswered posts | View active topics It is currently Fri Oct 24, 2014 4:32 am






Reply to topic  [ 3 posts ] 
Motor Sync 
Author Message
Rookie

Joined: Tue Dec 14, 2010 4:49 pm
Posts: 1
Post 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.


Fri Feb 18, 2011 7:58 pm
Profile
Novice
User avatar

Joined: Sat Jul 10, 2010 3:06 pm
Posts: 86
Location: Roanoke, VA
Post 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

_________________
Check out my website! www.RoboDesigners.com

VRC Team 2190

Twitter: @RoboDesigners


Fri Feb 18, 2011 11:38 pm
Profile WWW
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 405
Post 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
        }
    }

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

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Sat Feb 19, 2011 8:51 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.