View unanswered posts | View active topics It is currently Thu Jul 18, 2019 3:15 pm






Reply to topic  [ 2 posts ] 
getDistanceValue 
Author Message
Rookie

Joined: Wed Oct 01, 2014 12:35 pm
Posts: 3
Post getDistanceValue
This command seems to have a sonar that looks rearward from the standard Clawbot. I am trying to use it in the VEX Highrise Virtual World, which starts with the robot at one end of field and 3 cubes at the other end lined up along the robot's nominal direction of travel. If I move the robot forward the distance returned by the getDistanceValue keeps increasing as the robot approaches the first block in the line. If I turn the robot around by 180 degrees and move it backwards toward the blocks the distance decreases. The following code illustrates the problem:

#pragma config(StandardModel, "VEX IQ Clawbot")

task main()
{
// turnLeft(540,degrees,50);
setDistanceMaxRange(port7,1200);
float x=getDistanceValue(port7);
repeatUntil((x<100)||(x>2000)){
forward(1,seconds,20);
x=getDistanceValue(port7);
}
}

This code calculates an increasing value for x as the robot moves toward the blocks, eventually colliding with the blocks and pushing them off the field. If I uncomment the turnLeft command, and change the forward to a backward, the robot stops in front of the first block. What is wrong?


Mon Oct 06, 2014 3:33 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: getDistanceValue
Code:
forward(1,seconds,20);


The forward command may be the cause of your problems; when you use the forward command, the robot will move forward for the specified units (seconds), for the specified quantity (1), at the specified speed (20). During the forward movement, the robot will forward(1,seconds,20);NOT be checking any other sensors or loop conditions. Once the forward movement has completed, the robot will stop moving for 500 milliseconds and then move on to the next line in the program.

Instead of using the forward command, you can use the setMotor command to individually assign motor values to the IQ's motors:

Code:
repeatUntil((x<100)||(x>2000))
{
setMotor(rightMotor, 20);
setMotor(leftMotor, 20);

x=getDistanceValue(port7);
}


Once the robot has reached its target value range of either less than 100 or greater than 2000, you should stop the robot manually (you can use a stop() command to do so) to ensure that it comes to a complete stop when you want it to.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Tue Oct 14, 2014 6:09 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.