Turning Irobot with angles

14 replies [Last post]
vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 6 years 33 weeks ago.

Helo forum, Vaironl here.

I would like to know if there is a method I could use to turn the robot according to angles, or a radius. I'm not the best at math and therefore I din't try to make any calculations, but I can still understand many things. Please if possible can you guys provide me with efficient methods.

Doing science.

SEAL491
SEAL491's picture
Title: NooBot+
Joined: 07/19/2011
Posts:
BotPoints: 54
User offline. Last seen 6 years 23 weeks ago.

Hello Vaironl,

While I am also working on my own angle-turn function, I would like to note something I came across to ask the Botball Community

Here is a snippet of my code:

set_create_normalized_angle(0);

create_spin_CCW(40); <------- NOTE THIS LINE

while(get_create_normalized_angle(0.0) <= 45)
{
printf("%d\n", get_create_normalized_angle(0.0));
sleep(0.01);
}

create_stop();

I found that at lower speeds, the simulator completely overshoots (the create spins about 5 times to reach "45" degrees), but on higher speeds, the simulator is more accurate.

Is this a problem with the simulator or my code? In any case, this is frustrating because I am trying to create an acceleration profile (speed starting at 20 and goes up to the highest speed possible before slowing down) for turning.

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 3 years 29 weeks ago.

Hi Vaironl,

Can you clarify exactly what you're trying to do? Are you trying to have the Create turn in place by a certain angle? Or are you trying to have it drive in a circular arc with a certain radius? Both are possible; I'm just not sure what you're asking.

Thanks.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 3 years 29 weeks ago.

Hi SEAL491,

While I haven't tested your code, my guess is that this is a simulator bug. I developed a 3D Botball simulator (ImperiSim) and hacked the IC Botball simulator to handle the back-EMF motor commands, and based on my experience, I can say that getting simulators to accurately reflect reality is not an easy task, and in most cases, you're better off running your code on an actual robot.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS

vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 6 years 33 weeks ago.

Hello, SEAL491.

I'm sorry to disappoint you but I'm not a very good at CBC, and I might give you wrong information.

But if you would hear my opinion I think you can get an idea of whats going on.

When I test my basic programs of bumper collision, I see that the simulator at least before the 3.0.3 Update where very inaccurate.
The bump is detected but it keeps going, while the actual Irobot detects the bump perfectly.

Doing science.

vaironl
vaironl's picture
Title: NooBot+
Joined: 04/09/2011
Posts:
BotPoints: 27
User offline. Last seen 6 years 33 weeks ago.

I'm trying to stop turn 90degrees.
But now that you mention it turning while moving might be a good tip to have if you can provide it.

Doing science.

Marty Rand
Marty Rand's picture
Title: Botball Youth Advisory Council
Joined: 07/04/2009
Posts:
BotPoints: 253
User offline. Last seen 4 years 17 weeks ago.

For a lego bot:

The math for calculating the number of ticks per degree to turn in place would go something like this:

  1. TurnTimes=(DiamBot/DiamWheel);//Calculate how many times the wheel has to turn to turn 360 degrees (Distance between wheels / Diameter of wheel (printed on wheel))
  2. //and plug TurnTimes into this:
  3. TicksPerDegree=((TicksBlack*TurnTimes)/360);//Calculate ticks per degree of wheel rotation (ticks in a full wheel rotation for black motors (about 1100) * how many times the wheel has to turn to turn 360 degrees)/360

You would then multiply TicksPerDegree by the number of degrees you want to go. That will give you the number of ticks you need to turn. Plug that number into mrp like this:

  1. mrp(0,1000,TicksPerDegree*DegreesToTurn);
  2. mrp(3,1000,-TicksPerDegree*DegreesToTurn);
  3. bmd(0);
  4. bmd(3);

you will need to change the motor ports and - signs, but that should work

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}

Marty Rand
Marty Rand's picture
Title: Botball Youth Advisory Council
Joined: 07/04/2009
Posts:
BotPoints: 253
User offline. Last seen 4 years 17 weeks ago.

For a create:

  1. set_create_normalized_angle(0);
  2.  
  3. create_spin_CCW(40);
  4.  
  5. while(get_create_normalized_angle(0.0) <= 45)
  6. {
  7. msleep(5);
  8. printf("%d\n", get_create_normalized_angle(0.0));
  9. }
  10.  
  11. create_stop();

for clockwise turns you need a negative angle

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}

Marty Rand
Marty Rand's picture
Title: Botball Youth Advisory Council
Joined: 07/04/2009
Posts:
BotPoints: 253
User offline. Last seen 4 years 17 weeks ago.

You could put either of these in a function to simplify and shorten the code like this:

  1. int TicksPerDegree=0;
  2. int LegoTurnCalc(int DiamWheel, int DiamBot, int TicksBlack=1100)//run once to calculate the number of ticks per degree
  3. {
  4. int TurnTimes=(DiamBot/DiamWheel);//Calculate how many times the wheel has to turn to turn 360 degrees (Distance between wheels / Diameter of wheel (printed on wheel))
  5.  
  6. TicksPerDegree=((TicksBlack*TurnTimes)/360);//Calculates and returns ticks per degree of wheel rotation (ticks in a full wheel rotation for black motors (about 1100) * how many times the wheel has to turn to turn 360 degrees)/360
  7. }
  8. int LegoTurn(int LeftMotor, int RightMotor, int Speed, int DegreesToTurn)//a positive distance will turn the bot counter-clockwise (assuming you put the motor ports in the right places)
  9. {
  10. mrp(LeftMotor,Speed,-TicksPerDegree*DegreesToTurn);
  11. mrp(RightMotor,Speed,TicksPerDegree*DegreesToTurn);
  12. bmd(LeftMotor);
  13. bmd(RightMotor);
  14. }
  15.  
  16. int CreateTurn(int Speed, int Angle)
  17. {
  18. set_create_normalized_angle(0);
  19.  
  20. create_spin_CCW(Speed);
  21.  
  22.  
  23. if(Speed>0)
  24. {
  25. while(get_create_normalized_angle(0.0) <=Angle)
  26. {
  27. msleep(5);
  28. printf("%d\n", get_create_normalized_angle(0.0));
  29. }
  30.  
  31. }
  32.  
  33. else if(Speed<0)
  34. {
  35. while(get_create_normalized_angle(0.0) >=Angle)
  36. {
  37. msleep(5);
  38. printf("%d\n", get_create_normalized_angle(0.0));
  39. }
  40. }
  41.  
  42. create_stop();
  43. }

For the create function, a positive speed AND angle will yield a counter-clockwise turn. Put a negative speed AND Angle for a clockwise turn

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}

SEAL491
SEAL491's picture
Title: NooBot+
Joined: 07/19/2011
Posts:
BotPoints: 54
User offline. Last seen 6 years 23 weeks ago.

Is "msleep(5);" an adequate sleep time to make the create turn accurately? How accurate could you get the create to turn?

Marty Rand
Marty Rand's picture
Title: Botball Youth Advisory Council
Joined: 07/04/2009
Posts:
BotPoints: 253
User offline. Last seen 4 years 17 weeks ago.

Yes, but the real problem is that there is a variable lag between the create and the CBC that cannot be shortened. It isn't very long, but it will cause some error. That's why when you tell it to turn 90 degrees, it goes 90 - 95. It's not just because the create skids. The easiest way to fix it to backup into a wall with the flat back of the create. Go a little too far, so the create is flat against it. This will align you fairly well. If you have time, do it again with a perpendicular wall.

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}