| Author |
Message |
|
endazyar
Rookie
Joined: Sat Mar 16, 2013 4:18 pm Posts: 8
|
 Problem with turning the head of my robot for 90 degrees
Hello everyone, I'm currently building an explorer robot which can move its head(sonarSensor) to the right and left for 90 degrees to check the obstacles. I have implemented 2 functions for that. See them below; I have a trouble with moving the head to the left and back the position(front). When I call the functions separately they both work well. I mean when i just call checkLeft() function. It turns left and then back to the previous position. Same as for checkRight() function;however, when I call them in order, like checkLeft(); checkRight(); it passes the previous position about 22.5 more degrees. If you have an idea about what's wrong I'd be happy if you answer me. Also if you have any other ways to have exact turns, pls let me know. Thanks in advance.
|
| Sun Mar 17, 2013 12:15 pm |
|
 |
|
Kevin Selavko
Rookie
Joined: Thu May 31, 2012 4:06 pm Posts: 13 Location: Pittsburgh, Pa
|
 Re: Problem with turning the head of my robot for 90 degrees
Why do you have it returning only 45 degrees?
|
| Sun Mar 17, 2013 11:15 pm |
|
 |
|
Kevin Selavko
Rookie
Joined: Thu May 31, 2012 4:06 pm Posts: 13 Location: Pittsburgh, Pa
|
 Re: Problem with turning the head of my robot for 90 degrees
int sonarValue; int DIST; void resetEncoder(); void goToPosition(int pos); bool checkLeft(); bool checkRight();
task main() { resetEncoder(); while(true) { checkLeft(); checkRight(); } } void resetEncoder() // Put this somewhere at the start, this zero will be your center position { nMotorEncoder[motorA] = 0; // Set the encoder for Motor A to 0 }
void goToPosition(int pos) { if (nMotorEncoder[motorA] < pos ) { while(nMotorEncoder[motorA] < pos + 10) { motor[motorA] = 100; } while(nMotorEncoder[motorA] < 0) // Slow down the motor so it does not fly past { motor[motorA] = 25; } } else if (nMotorEncoder[motorA] > pos ) { while(nMotorEncoder[motorA] > pos-10) { motor[motorA] = -100; } while(nMotorEncoder[motorA] > pos) { motor[motorA] = -25; } motor[motorA] = 0; } } bool checkLeft(){ goToPosition(-90); sonarValue = SensorValue(sonarSensor); goToPosition(0);
if( sonarValue > DIST ){ return true; } else{ return false; } }
bool checkRight(){ goToPosition(90); sonarValue = SensorValue(sonarSensor); goToPosition(0); if( sonarValue > DIST ){ return true; } else{ return false; } }
|
| Mon Mar 18, 2013 12:32 am |
|
 |
|
endazyar
Rookie
Joined: Sat Mar 16, 2013 4:18 pm Posts: 8
|
 Re: Problem with turning the head of my robot for 90 degrees
Cause when i make it 90 degrees to return back, then it passes the previous position. When it was 45 it was a little bit ok. And thank you for your replies, I'll check your code now. Grateful.
|
| Tue Mar 19, 2013 11:38 am |
|
 |
|
endazyar
Rookie
Joined: Sat Mar 16, 2013 4:18 pm Posts: 8
|
 Re: Problem with turning the head of my robot for 90 degrees
When I call the functions just for once, and the code terminates the head doesn't get its previous position. it passes the previous position. Even When I just call checkLeft() it doesn't get the previous position. Couldn't figure out whats wrong with it :S
|
| Tue Mar 19, 2013 3:39 pm |
|
 |
|
Kevin Selavko
Rookie
Joined: Thu May 31, 2012 4:06 pm Posts: 13 Location: Pittsburgh, Pa
|
 Re: Problem with turning the head of my robot for 90 degrees
|
| Tue Mar 19, 2013 5:23 pm |
|
 |
|
endazyar
Rookie
Joined: Sat Mar 16, 2013 4:18 pm Posts: 8
|
 Re: Problem with turning the head of my robot for 90 degrees
Now it works well, thanks a lot!
|
| Tue Mar 19, 2013 5:35 pm |
|
 |
|
endazyar
Rookie
Joined: Sat Mar 16, 2013 4:18 pm Posts: 8
|
 Re: Problem with turning the head of my robot for 90 degrees
I still face the same problem. When I just use that function to turn the head to a side, and then set it to the previous position, it works. However when I use it among some code statements, the precision is not so good, the head starts flying to one side slowly. For example when I use the code below, it starts flying away slowly when motorB and motorC get power to go straight. Do you have any idea what it can be about ? Thanks in advance.
Last edited by endazyar on Tue Mar 26, 2013 4:35 am, edited 3 times in total.
|
| Sun Mar 24, 2013 1:38 pm |
|
 |
|
endazyar
Rookie
Joined: Sat Mar 16, 2013 4:18 pm Posts: 8
|
 Re: Problem with turning the head of my robot for 90 degrees
I still face the same problem, if anyone could help, I'd appreciate it.
|
| Sun Mar 24, 2013 2:21 pm |
|
|