ROBOTC.net forums
http://www.robotc.net/forums/

Trying to get Sonar Sensor to work on Autonomous
http://www.robotc.net/forums/viewtopic.php?f=52&t=3666
Page 6 of 6

Author:  MHTS [ Wed Dec 14, 2011 5:00 pm ]
Post subject:  Re: Trying to get Sonar Sensor to work on Autonomous

It looks like you changed the gate2 motor to a servo. Regardless, the problem is still the same that you compared the magnet sensor value to "1" that would never happen.
Code:
if(SensorValue[magnetSensor] > (NO_MAGNET_VALUE + MAGNET_THRESHOLD) || SensorValue[magnetSensor] < (NO_MAGNET_VALUE - MAGNET_THRESHOLD))
   //
   // If the magnetSenor is Inactive gate1 stays closed. If magnetSenor Is Active Servo3 opens, and gate1 closes
   //
   if(SensorValue[magnetSensor] == 1)

{
servo[servo3] = 127;
}
else
{
  servo[servo3] = 0;
}

So the proper code fix should be:
Code:
bool magnetPresent = abs(SensorValue[magnetSensor] - NO_MAGNET_VALUE) > MAGNET_THRESHOLD;
if (magnetPresent)
{
  servo[servo3] = 127;
}
else
{
  servo[servo3] = 0;
}

Author:  dtrain34555 [ Thu Dec 15, 2011 1:52 am ]
Post subject:  Re: Trying to get Sonar Sensor to work on Autonomous

Thanks i thought i waz the code wrong.

Page 6 of 6 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/