I am trying to program the ultrasonic sensor to initiate the front part of our feed mechanism on our robot, to both learn how to use it and to see if this application is practical.
The problem I am having is that when I run the code, the feed mech just runs, no matter what the sensor is reading. What it should be doing is running the feed mech anytime the sensor senses any something in that area, changing the value to something other than -1, and not run when it senses nothing, value equal -1. Can someone help me out here? I am running RobotC for Cortex and am fairly new to it coming from EasyC.
The Ultrasonic part
if(SensorValue[Sonar] != -1) //ultrasonic to operate the front feed
{
motor[FF]=127;
}
else
{
motor[FF]=0;
}
The Pragmas
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, dgtl1, Sonar, sensorSONAR_inch)
#pragma config(Sensor, I2C_1, RDIME, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, LDIME, sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port2, RD, tmotorVex393_MC29, openLoop, driveRight, encoderPort, I2C_1)
#pragma config(Motor, port3, LD, tmotorVex393_MC29, openLoop, driveLeft, encoderPort, I2C_2)
#pragma config(Motor, port4, RL, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, LL, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, MF, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, FF, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, RL, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port9, LL, tmotorVex393_MC29, openLoop)
The entire User Control
task usercontrol()
{
//sets IME's to Zero
nMotorEncoder[RD]=0;
nMotorEncoder[LD]=0;
while (true)
{
motor[LD]=.65*vexRT[Ch3]; //Drive
motor[RD]=vexRT[Ch2]; //Drive
motor[RL]=vexRT[Ch1]; //Launchers for test
motor[LL]=vexRT[Ch1]; //Launchers for test
if (vexRT[Btn5U]==1) //Feed on Left Front Buttons
{
motor[MF]=127;
}
else if(vexRT[Btn5D]==1)
{
motor[MF]=-127;
}
else
{
motor[MF]=0;
}
if(SensorValue[Sonar] != -1) //ultrasonic to operate the front feed
{
motor[FF]=127;
}
else
{
motor[FF]=0;
}
}
}