View unanswered posts | View active topics It is currently Thu Jul 31, 2014 6:56 pm






Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Need help with dimensions If else 
Author Message
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Post 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


Attachments:
Paralllel parking.c [1.44 KiB]
Downloaded 323 times
Tue Nov 02, 2010 2:16 pm
Profile
Moderator
Moderator
User avatar

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

I've created some pictures to illustrate the point:

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

Image
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.

Image
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.

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

Image
Step 5: Turn and start backing up.

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

Image
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
Profile WWW
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Post 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.


Attachments:
Paralllel parking.c [2.51 KiB]
Downloaded 325 times
Thu Nov 04, 2010 2:51 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post 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


Attachments:
Paralllel parking-Xander.c [2.82 KiB]
Downloaded 342 times

_________________
| 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
Profile WWW
Rookie

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

-Ziram


Thu Nov 04, 2010 7:17 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Post 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.


Attachments:
Paralllel parking.c [5.19 KiB]
Downloaded 318 times
Fri Nov 05, 2010 3:00 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

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


Sun Nov 07, 2010 3:06 pm
Profile
Rookie

Joined: Mon Nov 01, 2010 2:44 pm
Posts: 9
Post 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.


Attachments:
Paralllel parking.c [5.31 KiB]
Downloaded 329 times
Mon Nov 08, 2010 3:54 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 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 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.