View unanswered posts | View active topics It is currently Wed Aug 05, 2020 4:46 am

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
getDistanceValue
Author Message
Rookie

Joined: Wed Oct 01, 2014 12:35 pm
Posts: 3
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")

{
// 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

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 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    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    2014 Robotics Academy Summer of Learning