View unanswered posts | View active topics It is currently Mon Dec 22, 2014 10:05 pm






Reply to topic  [ 9 posts ] 
Turn specified degrees? 
Author Message
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 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


Sun Mar 02, 2008 12:46 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Sun Mar 02, 2008 7:22 pm, edited 5 times in total.



Sun Mar 02, 2008 2:44 pm
Profile
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 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


Sun Mar 02, 2008 5:07 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sun Mar 02, 2008 6:12 pm
Profile
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 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


Sun Mar 02, 2008 6:27 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
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);
}

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Sun Mar 02, 2008 7:17 pm, edited 4 times in total.



Sun Mar 02, 2008 7:02 pm
Profile
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post 
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


Sun Mar 02, 2008 7:06 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
see above!

you have to take the ABSOLUTE CORRECT measures!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sun Mar 02, 2008 7:11 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
have you got it?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Mar 11, 2008 6:54 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.