View unanswered posts | View active topics It is currently Sat Aug 30, 2014 2:19 pm






Reply to topic  [ 9 posts ] 
Problem with turning the head of my robot for 90 degrees 
Author Message
Rookie

Joined: Sat Mar 16, 2013 4:18 pm
Posts: 8
Post 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.

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
Profile
Rookie

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

_________________
SHARP
Sarah Heinz Advanced Robotics Program

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
Profile
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 22
Location: Pittsburgh, Pa
Post 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;
}
}

_________________
SHARP
Sarah Heinz Advanced Robotics Program

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
Profile
Rookie

Joined: Sat Mar 16, 2013 4:18 pm
Posts: 8
Post 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
Profile
Rookie

Joined: Sat Mar 16, 2013 4:18 pm
Posts: 8
Post 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
Profile
Rookie

Joined: Thu May 31, 2012 4:06 pm
Posts: 22
Location: Pittsburgh, Pa
Post 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
Sarah Heinz Advanced Robotics Program

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
Profile
Rookie

Joined: Sat Mar 16, 2013 4:18 pm
Posts: 8
Post 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
Profile
Rookie

Joined: Sat Mar 16, 2013 4:18 pm
Posts: 8
Post 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
Profile
Rookie

Joined: Sat Mar 16, 2013 4:18 pm
Posts: 8
Post 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
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.