View unanswered posts | View active topics It is currently Fri Apr 20, 2018 12:40 pm

 Page 1 of 2 [ 18 posts ] Go to page 1, 2  Next
 Print view Previous topic | Next topic
Need help with dimensions If else
Author Message
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Need help with dimensions If else
So i'm trying to have an if else statement where the NXT will move forwards with a sonar sensor looking for an opening along a wall at a certain distance then once it finds that distance i want it to see if that opening goes for more than that split second. For example the NXT goes forwards looking for something greater than 20cm away then once it finds it, it will then keep looking for that opening for 20 cms forwards so it sees that there is a box of 20x20

Thanks!

Mon Nov 01, 2010 2:52 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Need help with dimensions If else
Hi Ziram,

What have you managed to get done so far? Can you attach your code so we can see how to point you in the right direction?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Nov 02, 2010 4:08 am
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Re: Need help with dimensions If else
Here is the file. I just don't know how to make the robot keep going forwards for however long that 20cm opening is.

Thanks

Tue Nov 02, 2010 2:16 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Need help with dimensions If else
Ziram,

I've created some pictures to illustrate the point:

Step 1: Drive along the road and scan for an opening in the wall or row of cars

Step 2: Start of gap has been detected (your sonar sensor detects a much bigger distance). You make a note of your current wheel encoder count. This is the start of your distance measuring. Now you must drive along until the distance on your sonar sensor gets very small again. Then proceed to the next step.

Step 3: You detect the end of the gap. Once again, you make a note of your current wheel encoder count. This is the end of your distance measuring. Now you can subtract the start from the end and get the total distance travelled. IS this big enough for your car to fit in? If so, proceed to the next step.

Step 4: Drive ahead a little bit to make sure you're in the right position.

Step 5: Turn and start backing up.

Step 6: You're almost there, start turning the front wheels back into a straight position

Step 7: All done.

Does this clear things up?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Wed Nov 03, 2010 3:31 am
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Re: Need help with dimensions If else
Yes that makes it more clear! Can you show me some of the code as i am new to RobotC and not sure how to use the encoder.

-Thanks

Thu Nov 04, 2010 12:07 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Need help with dimensions If else
Try this code below. It displays the current values of the encoders as the motors run. You'll notice that one count increases faster than the other due to the difference in speed.

- Xander

 Code:#pragma config(Motor,  motorA,          MOTOR1,        tmotorNormal, PIDControl, encoder)#pragma config(Motor,  motorB,          MOTOR2,        tmotorNormal, PIDControl, encoder)//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//task main () {  long encoderCountMotor1 = 0;  long encoderCountMotor2 = 0;  // Reset the tachos for both motors.  You only need to do this  // once at the start of your program  nMotorEncoder[MOTOR1] = 0;  nMotorEncoder[MOTOR2] = 0;  wait1Msec(100);  // Start the motors  motor[MOTOR1] = 20;  motor[MOTOR2] = 60;  // Display the encoder counts in a nice way  nxtDisplayCenteredTextLine(0, "Motor Test");  nxtDrawLine(0, 52, 99, 52);  while (true) {    // Read the encoder counts.  You need to use a variable type called    // "long".  An "int" would not be big enough to handle all the possible    // values of the nMotorEncoder.    encoderCountMotor1 = nMotorEncoder[MOTOR1];    encoderCountMotor2 = nMotorEncoder[MOTOR2];    // Put the values on the screen    nxtDisplayTextLine(2, "Motor1: %5d", encoderCountMotor1);    nxtDisplayTextLine(3, "Motor2: %5d", encoderCountMotor2);    // Wait a little bit (50ms)    wait1Msec(50);  }}

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Thu Nov 04, 2010 2:30 am
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Re: Need help with dimensions If else
Ok I put that into the program and understand it but not sure how to tell the NXT to stop doing this when the gap closes then tell it to take the amount that the NXT traveled and see if that is enough space then if there is enough space back use like half of the distance it traveled and then back up.

Thu Nov 04, 2010 2:51 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Need help with dimensions If else
Take a look at this program. I have not tested it but it compiles. It is guaranteed to need work from you to make this work properly. I made it so you can get an idea.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Thu Nov 04, 2010 3:37 pm
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Re: Need help with dimensions If else
Quick question what does
Return;
do?

-Ziram

Thu Nov 04, 2010 7:17 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Need help with dimensions If else
return will exit the current function and go back to the point where it was called.

Take a look at the code below:
 Code:void function1 () {  // perform action 1     // perform action 2    if (condition == true) {    return; // exit the function, we're done  }     // perform action 3}task main () {  function1();  PlaySound(soundBeepBeep);  wait1Msec(1000);}

Take a good look at function1. Which actions are performed when condition is true? Which actions are performed when condition is false?

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Fri Nov 05, 2010 2:41 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Need help with dimensions If else
Here is a small video on how to get your car out of a tight space: http://vimeo.com/14592941

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Fri Nov 05, 2010 12:26 pm
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Re: Need help with dimensions If else
I think i have it just about done!
Haven't been able to test it yet but it looks good!

This has been a great learning experience.

Fri Nov 05, 2010 3:00 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Need help with dimensions If else
Looks good! Make sure you take a video of it when it is all working and I'll see if I can get it on the ROBOTC's community projects page on the official website!

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Fri Nov 05, 2010 4:54 pm
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Re: Need help with dimensions If else
Awesome! Will do!

Sun Nov 07, 2010 3:06 pm
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Re: Need help with dimensions If else
( ! )
Actually i have encountered a problem with the programming and i can't figure it out.
What is happening is the robot will do everything up until it has found a gap that is big enough for the robot to park.
The robot will find smaller ones and keep looking so there is nothing wrong there but once it has found a big enough spot the robot will just stop.
I have tried taking out the park(); function and seeing if it will just go back for 1 sec but nothing will work.

Mon Nov 08, 2010 3:54 pm
Display posts from previous:  Sort by
 Page 1 of 2 [ 18 posts ] Go to page 1, 2  Next

#### Who is online

Users browsing this forum: No registered users and 2 guests

 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