View unanswered posts | View active topics It is currently Fri Nov 28, 2014 2:57 am






Reply to topic  [ 1 post ] 
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.

Code:
#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:09 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: nicholas 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.