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

Turn specified degrees?
http://www.robotc.net/forums/viewtopic.php?f=1&t=425
Page 1 of 1

Author:  giannisAPI [ Sun Mar 02, 2008 12:46 pm ]
Post subject:  Turn specified degrees?

Hi,

Does anyone knows a way to tell nxt to turn a specified number of degrees?

90 or 180 for example?


Any help appreciated.


Regards,
giannis

Author:  Ford Prefect [ Sun Mar 02, 2008 2:44 pm ]
Post subject: 

ja, hier ist mein Vorschlag / my suggestion ? proposal ?:
du brauchst den Raddurchmesser /
you need the wheel diameter(DiameterWheel)
und den Abstand der beiden Antriebsr├Ąder /
distance of both wheels (WheelDistance):

Code:
int round(float f)
{
  if(f>0) return (int)(f + 0.5);
  else    return (int)(f - 0.5);
}

void turn_degr(float angle)
{
float DiameterWheel;   // cm , e.g. 8.2    
float WheelDistance;   //  cm , e.g. 12.0
int Ticks, speed;
float AnglePerTick;

AnglePerTick=DiameterWheel/WheelDistance;   

nMotorEncoder[1]=0;
nSyncedTurnRatio=-100;  // motors 1 + 2 to be synchronized!

Ticks=round(angle/AnglePerTick);


while(nMotorEncoder[1]!=Ticks)
{
if (abs(nMotorEncoder[1]-Ticks)>20){speed=30;}     
else speed=12;                                       
if (nMotorEncoder[1]<Ticks)
     {
       motor[1]=speed;
     }
     else
     if (nMotorEncoder[1]>Ticks)
     {
       motor[1]=-speed;
     }
   }
motor[1]=0;

}


void move_cm(float s)   // analog: to go straight
{

int Ticks, speed;

float DiameterWheel;   // cm       
float cmPerTick;   

cmPerTick=(PI*DiameterWheel)/360;   

nSyncedTurnRatio=100;  // motors 1 + 2 to be synchronized!

nMotorEncoder[1]=0; 
Ticks=round(s/cmPerTick);

while (Ticks!=nMotorEncoder[1])
  {
    if (abs(nMotorEncoder[1]-Ticks)>20) {speed=40;}     
else speed=15;                      
if (Ticks > nMotorEncoder[1]) {motor[1]=speed; }
    else
    if (Ticks < nMotorEncoder[1]) {motor[1]=-speed; }
  }
motor[1]=0;
}



if you're interested in a complete navigator program, please refer to
http://www.mindstormsforum.de/viewtopic.php?t=2875

HTH!

Author:  giannisAPI [ Sun Mar 02, 2008 5:07 pm ]
Post subject:  hi

Hi,

Could you please explain to me what you mean by "distance of both wheels (WheelDistance): "

I havent tested this but if this works, you have safed me a lot of time for my project :)

Thanks a lot for your help though.

Regards,
Giannis

Author:  Ford Prefect [ Sun Mar 02, 2008 6:12 pm ]
Post subject: 

Distance of the wheels - well , sorry for my poor English;
how else should I say?
the length of the axis?

Code:
#                     #
#                     #
#                     #
#  MM             MM  #
#- - - - -   - - - - -#
#  MM             MM  #
#                     #
#                     #
#                     #

^ left wheel          ^ right wheel
  with motor            with motor


^- - - - - - - - - - -^
    distance between
    left and right wheel

Author:  giannisAPI [ Sun Mar 02, 2008 6:27 pm ]
Post subject:  Hi

Hi again,

Oh no worries mine are not better ...:)

I did try this but the robot keeps going around forever.

Do i need to the parameters below as well:
float DiameterWheel; // cm , e.g. 8.2
float WheelDistance; // cm , e.g. 12.0
int Ticks, speed;
float AnglePerTick;

I called the function like this: turn_degr(90); with the WheelDistance set to 15 and the DiameterWheel set to 56 (which i dont think is in cm, it is written on the tire though. And it still keeps going around forever.

Would you know why please?


Regards,
Giannis

Author:  Ford Prefect [ Sun Mar 02, 2008 7:02 pm ]
Post subject: 

try it with a ruler... :wink:

?
float DiameterWheel= 5.6 ;
float WheelDistance=15.0 ;

notice:
// motorA =0
// motorB =1
// motorC =2
// to sync motors 1+2: nSyncedMotors = synchBC;

and then try this:

Code:
int round(float f)
{
  if(f>0) return (int)(f + 0.5);
  else    return (int)(f - 0.5);
}


float DiameterWheel=5.6  ;
float WheelDistance= 15.0 ;
float AnglePerTick;


void turn_degr(float angle)
{

int Ticks, speed;

nMotorEncoder[1]=0;
nSyncedTurnRatio=-100;  // motors 1 + 2 to be synchronized!

Ticks=round(angle/AnglePerTick);


while(nMotorEncoder[1]!=Ticks)
{
if (abs(nMotorEncoder[1]-Ticks)>20){speed=30;}
else speed=12;
if (nMotorEncoder[1]<Ticks)
     {
       motor[1]=speed;
     }
     else
     if (nMotorEncoder[1]>Ticks)
     {
       motor[1]=-speed;
     }
   }
motor[1]=0;

}

task main()
{
  AnglePerTick=DiameterWheel/WheelDistance;
  nSyncedMotors = synchBC;
  turn_degr(90);
}

Author:  giannisAPI [ Sun Mar 02, 2008 7:06 pm ]
Post subject: 

Hi,

I did try with a ruler but it stills keeps going around for ever.

I think the problem is because the variable AnglePerTick is 0.

Could you explain me what is this variable or what should i set it to please?


Kind Regards,
Ioannis

Author:  Ford Prefect [ Sun Mar 02, 2008 7:11 pm ]
Post subject: 

see above!

you have to take the ABSOLUTE CORRECT measures!

Author:  Ford Prefect [ Tue Mar 11, 2008 6:54 pm ]
Post subject: 

have you got it?

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