Author |
Message |
Ziram
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 |
|
 |
mightor
Site Admin
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 |
|
 |
Ziram
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 |
|
 |
mightor
Site Admin
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 |
|
 |
Ziram
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 |
|
 |
mightor
Site Admin
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 |
|
 |
Ziram
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 |
|
 |
mightor
Site Admin
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 |
|
 |
Ziram
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 |
|
 |
mightor
Site Admin
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: 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 |
|
 |
mightor
Site Admin
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 |
|
 |
Ziram
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!
Thanks for all your help! This has been a great learning experience.
|
Fri Nov 05, 2010 3:00 pm |
|
 |
mightor
Site Admin
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 |
|
 |
Ziram
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 |
|
 |
Ziram
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 |
|
|