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

POE Marble Sorter Code is not working
http://www.robotc.net/forums/viewtopic.php?f=69&t=13359
Page 1 of 1

Author:  coltonh [ Wed Feb 10, 2016 8:37 pm ]
Post subject:  POE Marble Sorter Code is not working

Hey guys, I'm having a problem with my code for my POE marble sorter. It runs but after I press my bump switch the motor with an encoder on it only moves in one direction and the servo to feed the marbles into the cups goes back and forth.

When I hit the button, it runs, but it starts my hopper motor and only moves one direction, meanwhile the servo keeps moving to 0 and -63.

I noticed that the quadrature encoder I have on the hopper motor so I can figure out where it is, resets to 0 every time it turns and drops a marble. So it keeps going in one direction randomly.

Thanks for any kind of help. Much appreciated.

Also, every time I compile and download to robot, an error comes up
Code:
***Error: Exception in Message sent from PC by ROBOTC IDE***:
Exception Type: 'System parm read out of range(19)'
Source: opcode message <SystemFunction> (0x67)
Exception Details: averageBatteryLevel(36)


Code:
#pragma config(Sensor, in1,    lightSensor,    sensorReflection)
#pragma config(Sensor, dgtl1,  startButton,    sensorTouch)
#pragma config(Sensor, dgtl2,  hopperEncoder,  sensorQuadEncoder)
#pragma config(Motor,  port2,           flashLight,    tmotorVexFlashlight, openLoop, reversed)
#pragma config(Motor,  port3,           feedMotor,     tmotorVex269_MC29, openLoop)
#pragma config(Motor,  port4,           hopperMotor,   tmotorVex269_MC29, openLoop)
#pragma config(Motor,  port5,           servoMotor,    tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
startMotor(flashLight, 127);
SensorValue(hopperEncoder) = 0;
setServo(servoMotor, -63);
untilTouch(startButton);

while(true)
   {
   startMotor(feedMotor, 30);
   if (SensorValue(lightSensor) <= 40 && SensorValue(lightSensor) => 30) //PLASTIC
      {
      wait1Msec(500);
      setServo(servoMotor, 0);
      wait1Msec(200);
      setServo(servoMotor, -63);
      }
   else
      {
      wait(2);
      if (SensorValue(lightSensor) <= 360 && SensorValue(lightSensor) => 340) //BLUE
         {
         startMotor(hopperMotor, 30);
         untilEncoderCounts(-86, hopperEncoder);
         stopMotor(hopperMotor);

         wait1Msec(500);
         setServo(servoMotor, 0[code][/code]);
         wait1Msec(200);
         setServo(servoMotor, -63);

         startMotor(hopperMotor, -30);
         untilEncoderCounts(0, hopperEncoder);
         stopMotor(hopperMotor);
         }
      else
         {
         if (SensorValue(lightSensor) <= 700 && SensorValue(lightSensor) => 650) //AL
         {
         startMotor(hopperMotor, 30);
         untilEncoderCounts(-271, hopperEncoder);
         stopMotor(hopperMotor);

         wait1Msec(500);
         setServo(servoMotor, 0);
         wait1Msec(200);
         setServo(servoMotor, -63);

         startMotor(hopperMotor, -30);
         untilEncoderCounts(0, hopperEncoder);
         stopMotor(hopperMotor);
         }
         else (SensorValue(lightSensor) <= 940 && SensorValue(lightSensor) => 920 ); //WOOD
            {
            startMotor(hopperMotor, 30);
            untilEncoderCounts(-175, hopperEncoder);
            stopMotor(hopperMotor);

            wait1Msec(500);
            setServo(servoMotor, 0);
            wait1Msec(200);
            setServo(servoMotor, -63);

            startMotor(hopperMotor, -30);
            untilEncoderCounts(0, hopperEncoder);
            stopMotor(hopperMotor);
            } //last else
         } // ends 2nd last else
      } // ends first else
   } //ends while loop
} // ends whole program

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