View unanswered posts | View active topics It is currently Tue Feb 09, 2016 11:56 am

 Page 1 of 1 [ 9 posts ]
 Print view Previous topic | Next topic
Problem with turning the head of my robot for 90 degrees
Author Message
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.

 Code:bool checkLeft(){  nMotorEncoder[motorA] = 0;  // Set the encoder for Motor A to 0  while(nMotorEncoder[motorA] >= -90){  motor[motorA] = -100;  }  motor[motorA] = 0;  sonarValue = SensorValue(sonarSensor);  /********** return right *********/  nMotorEncoder[motorA] = 0;  while(nMotorEncoder[motorA] <= 45){  motor[motorA] = 100;  }  motor[motorA] = 0;  /*********************************/    nMotorEncoder[motorA] = 0;  if( sonarValue > DIST ){    return true;  }  else{    return false;  }}bool checkRight(){  nMotorEncoder[motorA] = 0;  while(nMotorEncoder[motorA] <= 90){  motor[motorA] = 100;  }  motor[motorA] = 0;  sonarValue = SensorValue(sonarSensor);  /*********** return left ***********/  nMotorEncoder[motorA] = 0;  while(nMotorEncoder[motorA] > -45){  motor[motorA] = -100;  }  motor[motorA] = 0;  /**********************************/    nMotorEncoder[motorA] = 0;    if( sonarValue > DIST ){    return true;  }  else{    return false;  }}

Sun Mar 17, 2013 12:15 pm
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 25
Location: Pittsburgh, Pa
Re: Problem with turning the head of my robot for 90 degrees
Why do you have it returning only 45 degrees?

_________________
SHARP

VEX 889A and FIRST 3260

Pittsburgh Champions Aerial Assist 2014
Pittsburgh and Buckeye Finalist Ultimate Ascent 2013
Toss Up Champions and Excellence-Pittsburgh
Toss Up Champions-Northwest Maryland VRC

Sun Mar 17, 2013 11:15 pm
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 25
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();

{
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;
}
}

_________________
SHARP

VEX 889A and FIRST 3260

Pittsburgh Champions Aerial Assist 2014
Pittsburgh and Buckeye Finalist Ultimate Ascent 2013
Toss Up Champions and Excellence-Pittsburgh
Toss Up Champions-Northwest Maryland VRC

Mon Mar 18, 2013 12:32 am
Rookie

Joined: Sat Mar 16, 2013 4:18 pm
Posts: 8
Re: Problem with turning the head of my robot for 90 degrees
 Kevin Selavko wrote:Why do you have it returning only 45 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
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
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 25
Location: Pittsburgh, Pa
Re: Problem with turning the head of my robot for 90 degrees
 Code:#pragma config(Sensor, S1,     sonarSensor,    sensorSONAR)//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//int sonarValue;int DIST;void resetEncoder() {   nMotorEncoder[motorA] = 0;}void goTo(int pos){   while(nMotorEncoder[motorA] != pos)   {      motor[motorA]   = (pos - nMotorEncoder[motorA]);   }   motor[motorA]   = 0;}bool checkLeft(){   goTo(-90);   sonarValue = SensorValue(sonarSensor);   goTo(0);   if( sonarValue > DIST )      return true;   else      return false;}bool checkRight(){   goTo(90);   sonarValue = SensorValue(sonarSensor);   goTo(0);   if( sonarValue > DIST )      return true;   else      return false;}task main{   resetEncoder();   while(true)   {      checkRight();      checkLeft();   }}

_________________
SHARP

VEX 889A and FIRST 3260

Pittsburgh Champions Aerial Assist 2014
Pittsburgh and Buckeye Finalist Ultimate Ascent 2013
Toss Up Champions and Excellence-Pittsburgh
Toss Up Champions-Northwest Maryland VRC

Tue Mar 19, 2013 5:23 pm
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
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.

 Code:#pragma config(Sensor, S4,     sonarSensor,         sensorSONAR)bool checkLeft(){   resetEncoder();   goTo(-90);   sonarValue = SensorValue(sonarSensor);   goTo(0);   if( sonarValue > 18 )      return true;   else      return false;}task main(){  checkLeft();  motor[motorB] =100;  motor[motorC] =100;  wait1Msec(3000);  motor[motorB] = 0;  motor[motorC] = 0;}

Last edited by endazyar on Tue Mar 26, 2013 4:35 am, edited 3 times in total.

Sun Mar 24, 2013 1:38 pm
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 9 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    2014 Robotics Academy Summer of Learning    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge