ROBOTC.net forums
http://www.robotc.net/forums/

getDistanceValue
http://www.robotc.net/forums/viewtopic.php?f=69&t=9497
Page 1 of 1

Author:  gottliebpet [ Mon Oct 06, 2014 3:33 am ]
Post subject:  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?

Author:  JohnWatson [ Tue Oct 14, 2014 6:09 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/