Hi Peeps,
One of my friend’s (whose account is not getting certified) team needs help. Their wheel motors move without any commands being given to them. (Commands are there but only when you move joysticks) This is the code:
*#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Sensor, I2C_3, , sensorQuadEncoderOnI2CPort, , AutoAssign )
#pragma config(Motor, port1, LeftgoalMtr, tmotorVex393_HBridge, openLoop)
#pragma config(Motor, port3, ArmMtrLeft, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, ClawMtr, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port5, ArmMtrRight, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, RightbackMtr, tmotorVex393_MC29, PIDControl, encoderPort, I2C_3)
#pragma config(Motor, port8, RightfrontMtr, tmotorVex393_MC29, PIDControl, reversed, encoderPort, I2C_2)
#pragma config(Motor, port9, LeftfrontMtr, tmotorVex393_MC29, PIDControl, encoderPort, I2C_1)
#pragma config(Motor, port10, RightgoalMtr, tmotorVex393_HBridge, openLoop, reversed)
//!!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)
#pragma autonomousDuration(20)
#pragma userControlDuration(60)
//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()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks
// running between Autonomous and Driver controlled modes. You will need to
// manage all user created tasks if set to false.
bStopTasksBetweenModes = true;
// Set bDisplayCompetitionStatusOnLcd to false if you don't want the LCD
// used by the competition include file, for example, you might want
// to display your team name on the LCD in this function.
// bDisplayCompetitionStatusOnLcd = false;
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/---------------------------------------------------------------------------/
/* */
/* 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. */
/---------------------------------------------------------------------------/
void waitforencoders()
{
waitUntilMotorStop(LeftfrontMtr);
waitUntilMotorStop(RightfrontMtr);
waitUntilMotorStop(RightbackMtr);
}
void resetencoder()
{
resetMotorEncoder(RightbackMtr);
resetMotorEncoder(LeftfrontMtr);
resetMotorEncoder(RightfrontMtr);
}
task autonomous()
{
resetencoder();
setMotorTarget(LeftfrontMtr, nEncoderCountTarget, 127, true);
setMotorTarget(RightfrontMtr, nEncoderCountTarget, 127, true);
setMotorTarget(RightbackMtr, nEncoderCountTarget, 127, true);
waitforencoders();
resetencoder();
motor(RightgoalMtr) = 127;
motor(LeftgoalMtr) = 127;
wait10Msec(700);
setMotorTarget(LeftfrontMtr, nEncoderCountTarget, -127, true);
setMotorTarget(RightfrontMtr, nEncoderCountTarget, 127, true);
setMotorTarget(RightbackMtr, nEncoderCountTarget, 127, true);
// ..........................................................................
// Insert user code here. 1.84 rotation from start to goal
// ..........................................................................
}
/---------------------------------------------------------------------------/
/* */
/* 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()
{
// User control code here, inside the loop
while (true)
{
resetencoder();
motor(RightbackMtr) = vexRT[Ch2];
motor(RightfrontMtr) = vexRT(Ch2);
motor(LeftfrontMtr) = vexRT[Ch3];
if (vexRT[Btn6U] == 1)
{
motor(ArmMtrLeft) = 80;
motor(ArmMtrRight) = 80;
}
else if (vexRT[Btn6D] == 1)
{
motor(ArmMtrLeft) = -80;
motor(ArmMtrRight) = -80;
}
else
{
motor(ArmMtrLeft) = 0;
motor(ArmMtrRight) = 0;
}
if (vexRT[Btn5U] == 1)
{
motor(LeftgoalMtr) = 20; //This speed will change as it is the speed of the mobile goal holder move.
motor(RightgoalMtr) = 20; //Same here.
}
else if (vexRT[Btn5U] == 0)
{
motor(LeftgoalMtr) = 0;
motor(RightgoalMtr) = 0;
}
if (vexRT[Btn5D] == 1)
{
motor(LeftgoalMtr) = -20;
motor(RightgoalMtr) = -20;
}
else if (vexRT[Btn5D] == 0)
{
motor(LeftgoalMtr) = 0;
motor(RightgoalMtr) = 0;
}
if (vexRT[Btn7R] == 1)
{
motor(ClawMtr) = 25;
wait1Msec(600);
motor(ClawMtr) = 0;
}
else if(vexRT[Btn7L] == 1)
{
motor(ClawMtr) = -25;
wait1Msec(600);
motor(ClawMtr) = 0;
}
}
*}
Please Respond if you know how to help, and feel free to ask questions about any further things that you need to know to help us.
THANK YOU!!!