|
Page 1 of 1
|
[ 9 posts ] |
|
If-Else, Ultrasonic & Bumper
Author |
Message |
emwbjr
Rookie
Joined: Wed Apr 14, 2010 11:09 am Posts: 6
|
 If-Else, Ultrasonic & Bumper
I've attempted to program my robot to have the servos move back and forth based on certain conditions. I wanted them to begin moving when the Ultrasonic sensor detected something less than 12in away. And if it detected nothing, the servos wouldn't move. The second If-Else statement was to make the servos move if the bumper is pressed. The problem may be with the "//...//" notes, not sure. The servos seem to move automatically, regardless of the stimulus, and the button doesn't seem to make anything happen yet. My code is as follows, slightly shortened:
|
Tue Apr 27, 2010 12:26 pm |
|
 |
Gary Samad
Expert
Joined: Mon Mar 15, 2010 4:24 pm Posts: 124
|
 Re: If-Else, Ultrasonic & Bumper
Well, there is no problem with the comments, although you don't need the "//" at the end of the line. Have you tried just reading the sonarSensor and displaying the value?
Gary
|
Tue Apr 27, 2010 6:14 pm |
|
 |
emwbjr
Rookie
Joined: Wed Apr 14, 2010 11:09 am Posts: 6
|
 Re: If-Else, Ultrasonic & Bumper
I have not, but I'm not sure how to do that.
|
Tue Apr 27, 2010 9:13 pm |
|
 |
bluesaberist
Rookie
Joined: Sat Nov 22, 2008 8:06 pm Posts: 48
|
 Re: If-Else, Ultrasonic & Bumper
You can make it display sensor values using the RobotC debugger. All you need is to have the sensor set up properly.
I suggest you try replacing
if(SensorValue(Button)==1)
with this:
if(SensorValue(Button)==0)
I think the buttons may have inverted logic.
This probably isn't what is causing the problem, but you should be setting up the servos/motors in the motor and sensor setup menu.
|
Wed Apr 28, 2010 12:31 am |
|
 |
emwbjr
Rookie
Joined: Wed Apr 14, 2010 11:09 am Posts: 6
|
 Re: If-Else, Ultrasonic & Bumper
I tried switching the bumpers, and I'm not the most proficient debugger. I brought the menu up, and I can see the sensors, but I can't tell their actual values, the change but not due to what I actually do to it.
|
Wed Apr 28, 2010 12:45 pm |
|
 |
Gary Samad
Expert
Joined: Mon Mar 15, 2010 4:24 pm Posts: 124
|
 Re: If-Else, Ultrasonic & Bumper
I'm not sure your #pragma statements look right. You might want to go back to the sensor setup window and verify that you have the appropriate sensor set up on the correct port.
Gary
|
Wed Apr 28, 2010 4:21 pm |
|
 |
huoxueren
Rookie
Joined: Wed Jul 20, 2011 4:52 am Posts: 1
|
 a
Appreciate the info, it’s good to know.
_________________ [u=http://www.timberlandmark.com]timberland shoes[/u]
|
Thu Jul 21, 2011 10:30 pm |
|
 |
Eddie
Rookie
Joined: Tue Jul 26, 2011 8:19 pm Posts: 15
|
 Re: If-Else, Ultrasonic & Bumper
I'm pretty sure that both the button and SONAR are digital sensors. In which case, you need to make sure that you have them set up as such in RobotC and on the robot. Also, I may have this wrong but I'm under the impression that the SONAR cable 1 should be in port 5 followed by the SONAR cable 2 in port 6. Try using this for your #pragma and make sure that the sensors are plugged into the corresponding digital ports.
_________________ Member of the Sarah Heinz House VEX and FIRST teams.
|
Fri Sep 23, 2011 7:23 pm |
|
 |
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 409
|
 Re: If-Else, Ultrasonic & Bumper
If you want to have the code repeat or "go back and forth" you'll need to put all of the code in task main in a while loop: http://www.robotc.net/vex_full/reference/hp_while.pdf
|
Fri Sep 23, 2011 8:32 pm |
|
|
|
Page 1 of 1
|
[ 9 posts ] |
|
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
|
|