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:

bMotorReflected[port3]= 1;motor[port2]= -50; // This simply makes the left side of the jaw move //motor[port3]= -50; // This makes the right side of the jaw move //wait1Msec (200); // Time before the mouth to move back up //motor[port2]= 45;motor[port3]= 45;wait1Msec (200); // Time before the mouth moves back down //motor[port2]= -50;motor[port3]= -50;wait1Msec (200);motor[port2]= 45;motor[port3]= 45;wait1Msec (200);

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

Author:

emwbjr [ Tue Apr 27, 2010 9:13 pm ]

Post subject:

Re: If-Else, Ultrasonic & Bumper

I have not, but I'm not sure how to do that.

Author:

bluesaberist [ Wed Apr 28, 2010 12:31 am ]

Post subject:

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.

Author:

emwbjr [ Wed Apr 28, 2010 12:45 pm ]

Post subject:

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.

Author:

Gary Samad [ Wed Apr 28, 2010 4:21 pm ]

Post subject:

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

Author:

huoxueren [ Thu Jul 21, 2011 10:30 pm ]

Post subject:

a

Appreciate the info, it&rsquo;s good to know.

Author:

Eddie [ Fri Sep 23, 2011 7:23 pm ]

Post subject:

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.