View unanswered posts | View active topics It is currently Sun Nov 23, 2014 4:39 am






Reply to topic  [ 4 posts ] 
Help me sync motors 
Author Message
Rookie

Joined: Tue Feb 11, 2014 9:15 pm
Posts: 4
Post Help me sync motors
Hi I've been trying to make a robot that solves a simple maze, but I recently notice that if the robot doesn't move straight, it creates a problem and falls over. I have tried syncing the motors using this(see attachment or program) but it seem that the robot is now not turning when it's required to. Without the synced motors command it turns perfectly fine and works well, but trying to keep the motors in sync was confusing to me. I'm begging you to help me sync the motors and have it solve my maze.

Here's the entire thing.

#pragma config(Sensor, S1, wall, sensorSONAR)
#pragma config(Motor, motorA, right, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, motorC, left, tmotorNXT, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

float en=0;
int m=0;
float wheelD=2.18;
float dt=0;
float dc=4.75;






void turnExactdistance1 (float o)
{
dt=(o*PI*dc)/2;
nMotorEncoder[left]=0;
en=(dt*360)/(PI*wheelD)-22;
motor[right]=-25;
motor[left]=25;
while(nMotorEncoder[left]<en)
{}
motor[right]=0;
motor[left]=0;
}

void turnExactdistance (float o)
{
dt=(o*PI*dc)/2;
nMotorEncoder[right]=0;
en=(dt*360)/(PI*wheelD)-22;
motor[right]=25;
motor[left]=-25;
while(nMotorEncoder[right]<en)
{}
motor[right]=0;
motor[left]=0;
}





task main()
{
while(m==0)
{


if(SensorValue[wall]>18)
{
nSyncedMotors = synchAC;
nSyncedTurnRatio = 100;
motor[motorA] = 75;
}

else
{
motor[right]=0;
motor[left]=0;
wait1Msec(250);
m=2;

}


while(m==2)
{

if(SensorValue[wall]<18)
{
motor[left]=0;
motor[right]=0;
wait1Msec(250);
turnExactdistance(.5);
wait1Msec(500);
m=3;
}

while(m==3)
{

if(SensorValue[wall]<18)
{
motor[left]=0;
motor[right]=0;
wait1Msec(250);
turnExactdistance1(1);
wait1Msec(500);
motor[left]=0;
motor[right]=0;
wait1Msec(250);
m=0;
}

else
{
m=0;
}
}
}
}
}


Tue Feb 11, 2014 10:10 pm
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 184
Post Re: Help me sync motors
I think a problem you might be having is in this section of code:

Code:
if(SensorValue[wall]>18)
{
  nSyncedMotors = synchAC;
  nSyncedTurnRatio = 100;
  motor[motorA] = 75;
}


Once you set nSyncedMotors to synchAC and nSyncedTurnRatio to 100, motors A and C will stay synched together doing a turn for the rest of the program. If you want to make them go straight, you need to set nSyncedTurnRatio to 0. And, if you don't want them synced anymore, you can set nSyncedMotors to synchNone.

P.S. Helpful hint: If you put [_CODE] [_/CODE] tags (without the underscores) around your code in your post, it will preserve the formatting and make it much easier to read! :bigthumb:

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Wed Feb 12, 2014 7:42 pm
Profile
Rookie

Joined: Tue Feb 11, 2014 9:15 pm
Posts: 4
Post Re: Help me sync motors
I have tried nsyncmotor=0; but it seems that the robot is moving in a circle, which means that only one motor runs, please help me with other suggestions.


Wed Feb 12, 2014 8:33 pm
Profile
Rookie

Joined: Tue Feb 11, 2014 9:15 pm
Posts: 4
Post Re: Help me sync motors
I'm sorry I misread your post, i understand now and it works, thank you very much.


Wed Feb 12, 2014 8:39 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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:  
cron



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