We are doing a CIM Factory for class and it owrks by pressing buttons and then going to what you selected to make something.
its not working and we don’t know why. HELP.
#pragma config(Sensor, dgtl5, leftEncoder, sensorQuadEncoder)
#pragma config(Sensor, dgtl7, rightEncoder, sensorQuadEncoder)
#pragma config(Motor, port2, VexTwist, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port3, VexTower, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port5, VexClaw, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port6, leftMotor, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port7, rightMotor, tmotorVex269_MC29, openLoop)
#pragma config(Motor, port8, Slider, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
/---------------------------------------------------------------------------/
/* /
/ Description: Competition template for VEX EDR /
/ /
/---------------------------------------------------------------------------*/
// This code is for the VEX cortex platform
#pragma platform(VEX2)
// Select Download method as “competition”
#pragma competitionControl(Competition)
//Main competition background code…do not modify!
#include “Vex_Competition_Includes.c”
/---------------------------------------------------------------------------/
/* Pre-Autonomous Functions /
/ /
/ You may want to perform some actions before the competition starts. /
/ Do them in the following function. You must return from this function /
/ or the autonomous and usercontrol tasks will not be started. This /
/ function is only called once after the cortex has been powered on and /
/ not every time that the robot is disabled. /
/---------------------------------------------------------------------------*/
void pre_auton ()
{
}
void driveFront(int front)
{
int masterPower1 = 125; //do not set this at 127 because the slave power will not be able to go over
int slavePower1 = 125;
int error1 = 0;
int kp1 = 5;
//Reset the encoders.
SensorValue[leftEncoder] = 0;
SensorValue[rightEncoder] = 0;
while((SensorValue[leftEncoder]) < front)// move forward to stars
{
//Set the motor powers to their respective variables.
motor[leftMotor] = masterPower1;
motor[rightMotor] = slavePower1;
error1 = SensorValue[leftEncoder] - SensorValue[rightEncoder];
slavePower1 += error1 / kp1;
wait1Msec(100);
}
motor[leftMotor] = -20;
motor[rightMotor] = -20;
wait1Msec(250);
motor[leftMotor] = 0;
motor[rightMotor] = 0;
}
void driveBack(int back)
{
int masterPower = -125;
int slavePower = -125;
int error = 0;
int kp = 15;
//Reset the encodback
SensorValue[leftEncoder] = 0;
SensorValue[rightEncoder] = 0;
wait1Msec(500);
//Repeat ten times a second.
while((SensorValue[leftEncoder]*-1) < back)
{
//Set the motor powers to their respective variables.
motor[leftMotor] = masterPower;
motor[rightMotor] = slavePower;
error = SensorValue[leftEncoder] - SensorValue[rightEncoder];
slavePower += error / kp;
wait1Msec(100);
}
motor[leftMotor] = 20;
motor[rightMotor] = 20;
wait1Msec(250);
motor[leftMotor] = 0;
motor[rightMotor] = 0;
wait1Msec(100); //pause one second
}
/---------------------------------------------------------------------------/
/* /
/ Autonomous Task /
/ /
/ This task is used to control your robot during the autonomous phase of /
/ a VEX Competition. /
/ /
/ You must modify the code to add your own robot specific commands here. /
/---------------------------------------------------------------------------*/
task autonomous()
{
// Remove this function call once you have "real" code.
AutonomousCodePlaceholderForTesting();
}
/---------------------------------------------------------------------------/
/* /
/ User Control Task /
/ /
/ This task is used to control your robot during the user control phase of /
/ a VEX Competition. /
/ /
/ You must modify the code to add your own robot specific commands here. /
/---------------------------------------------------------------------------*/
task usercontrol()
{
//customer picking
if (vexRT[Btn5U] == 1)
{
while (vexRT[Btn5U] == 1)
{
driveFront(500);
}
}
if (vexRT[Btn6U] == 1)
{
while (vexRT[Btn6U] == 1)
{
driveFront(750);
}
}
if (vexRT[Btn7U] == 1)
{
while (vexRT[Btn7U] == 1)
{
driveFront(1000);
}
}
if (vexRT[Btn8U] == 1)
{
while (vexRT[Btn8U] == 1)
{
driveFront(1250);
}
}
}