Robot C Code Help

We are trying to have our robot “suck” up balls (motor titled goodSuck) for the 2018 game and then launch the ball by using a crossbow-type launching mechanism (motor titled yeeter). All of our driver controls work except driver controls for the intake and launching mechanisms. We have tried replacing and isolating everything so we are confident the code is where the error is occurring. The attached photo is the code for those two driver controls. Can you please let me know what I am doing wrong for this code?

1 Like

Can you post all of the code? Remember to put it inside the [code] tags.

You forgot to put your code inside a/the while loop

Can you please show me what you mean? I am not very knowledgeable about robot C.

#pragma config(Motor, port2, rightf, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port3, rightmb, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port4, leftf, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port5, leftmb, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port6, flipper, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, goodSuck, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, yeeter, 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()
{
// 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. /
/
---------------------------------------------------------------------------*/

task autonomous()
{
motor[flipper] = 127;
wait1Msec(450);
motor[flipper] = 0;//flipperUp

motor[rightf] = 127;
motor[rightmb] = 127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//forward--Step 1
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

motor[rightf] = -127;
motor[rightmb] = -127;
motor[leftf] = -127;
motor[leftmb] = -127;
wait1Msec(450);//backwards--Step 2
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop
motor[rightf] = -127;
motor[rightmb] = -127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//turnRight
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

motor[rightf] = 127;
motor[rightmb] = 127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//forward--Step 3
motor[flipper] = 127;

wait1Msec(450);
motor[flipper] = 0;//flipperUp
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

motor[rightf] = -127;
motor[rightmb] = -127;
motor[leftf] = -127;
motor[leftmb] = -127;
wait1Msec(450);//backwards--Step 4
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop
motor[rightf] = 127;
motor[rightmb] = 127;
motor[leftf] = -127;
motor[leftmb] = -127;
wait1Msec(450);//turnLeft
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

motor[rightf] = 127;
motor[rightmb] = 127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//forward--Step 5
motor[flipper] = 127;

wait1Msec(450);
motor[flipper] = 0;//flipperUp
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

motor[rightf] = -127;
motor[rightmb] = -127;
motor[leftf] = -127;
motor[leftmb] = -127;
wait1Msec(450);//backwards--Step 6
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop
motor[rightf] = -127;
motor[rightmb] = -127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//turnRight
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

motor[rightf] = 127;
motor[rightmb] = 127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//forward--Step 7
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop
motor[rightf] = -127;
motor[rightmb] = -127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//turnRight
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

motor[rightf] = 127;
motor[rightmb] = 127;
motor[leftf] = 127;
motor[leftmb] = 127;
wait1Msec(450);//forward--Step 8
motor[rightf] = 0;
motor[rightmb] = 0;
motor[leftf] = 0;
motor[leftmb] = 0;//stop

}

/---------------------------------------------------------------------------/
/* /
/
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()
{

while (true)
{
//drive system
motor[leftf] =vexRT(Ch3);
motor[leftmb] = vexRT(Ch3);
motor[rightf] = vexRT(Ch2);
motor[rightmb] = vexRT(Ch2);
//flipper
if(vexRT[Btn5U] == 1){
motor[flipper] = 127;
motor[flipper] = 127;
}
else if(vexRT[Btn5D] ==1)
{
motor[flipper] = -64;
motor[flipper] = -64;
}
else{
motor[flipper] = 0;
motor[flipper] = 0;
}
}
//goodSuck
if (vexRT[Btn6U] == 1){
motor[goodSuck] = 127;
}//else {
//motor[goodSuck] = 0;}
//yeeter
if (vexRT[Btn6D] == 1){
motor[yeeter] = 127;
}//else {
// motor[yeeter] = 0;}
}

It is really difficult to read your code. Please add [code] at the beginning of the post and [/ code](without the space) at the end of the post so it turns the format that you posted into something more readable.
If you have code such as

task main(){
//Insert statements here
}

whatever is inside the brackets will run only once. In order to make the code run indefinitely you would need to do

task main(){
while(true){
//Insert statements here
}
}

And whatever is in the brackets of while(true) will run repeatedly until you turn the robot off.

This is my while statement. Could you look over it as a whole and see if you can find the error?

while (true)
{
//drive system
motor[leftf] =vexRT(Ch3);
motor[leftmb] = vexRT(Ch3);
motor[rightf] = vexRT(Ch2);
motor[rightmb] = vexRT(Ch2);
//flipper
if(vexRT[Btn5U] == 1){
motor[flipper] = 127;
motor[flipper] = 127;
}
else if(vexRT[Btn5D] ==1)
{
motor[flipper] = -64;
motor[flipper] = -64;
}
else{
motor[flipper] = 0;
motor[flipper] = 0;
}

//goodSuck
if (vexRT[Btn6U] == 1){
  motor[goodSuck] = 127;
}//else {
  //motor[goodSuck] = 0;}
//yeeter
if (vexRT[Btn6D] == 1){
  motor[yeeter] = 127;
}//else {
 // motor[yeeter] = 0;}
	}

}

In case I didn’t mention it earlier, this is a VEX Competition template.

Try replacing your usercontrol to this. I found the missing curly bracket which was near where the flipper was. If you have only one statement you are using, you could remove the curly brackets and replace it to just your simple statement instead. The curly brackets only define when there is multiple statements(Or actions) that would like to be ran if a condition is set.

task usercontrol()
{

while (true)
{
//drive system
motor[leftf] = vexRT(Ch3);
motor[leftmb] = vexRT(Ch3);
motor[rightf] = vexRT(Ch2);
motor[rightmb] = vexRT(Ch2);
//flipper
if(vexRT[Btn5U]) motor[flipper] = 127;
else if(vexRT[Btn5D]) motor[flipper] = -64;
else motor[flipper] = 0;
//goodSuck
if (vexRT[Btn6U]) motor[goodSuck] = 127;
//else {
//motor[goodSuck] = 0;}
//yeeter
if (vexRT[Btn6D]) motor[yeeter] = 127;
//else {
// motor[yeeter] = 0;}
}
}
1 Like
#pragma config(Motor, port2, rightf, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port3, rightmb, tmotorVex393_MC29, openLoop, driveRight)
#pragma config(Motor, port4, leftf, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port5, leftmb, tmotorVex393_MC29, openLoop, driveLeft)
#pragma config(Motor, port6, flipper, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, goodSuck, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port8, yeeter, tmotorVex393_MC29, openLoop)
// *!!Code automatically generated by ‘ROBOTC’ configuration wizard !!* //


/ *---------------------------------------------------------------------------* /
/* <em>/
/</em> User Control Task <em>/
/</em> <em>/
/</em> This task is used to control your robot during the user control phase of <em>/
/</em> a VEX Competition. <em>/
/</em> <em>/
/</em> You must modify the code to add your own robot specific commands here. <em>/
/</em> ---------------------------------------------------------------------------*/

task usercontrol()
{

while (true)
{
//drive system
motor[leftf] =vexRT(Ch3);
motor[leftmb] = vexRT(Ch3);
motor[rightf] = vexRT(Ch2);
motor[rightmb] = vexRT(Ch2);
//flipper
if(vexRT[Btn5U] == 1){
motor[flipper] = 127;
motor[flipper] = 127;
}
else if(vexRT[Btn5D] ==1)
{
motor[flipper] = -64;
motor[flipper] = -64;
}
else{
motor[flipper] = 0;
motor[flipper] = 0;
}
}  // This is an extra } that closes off the while (true) loop  REMOVE IT
//goodSuck
if (vexRT[Btn6U] == 1){
motor[goodSuck] = 127;
}//else {
//motor[goodSuck] = 0;}
//yeeter
if (vexRT[Btn6D] == 1){
motor[yeeter] = 127;
}//else {
// motor[yeeter] = 0;}
}
} // Extra curly needed here
1 Like

Some good coding advice is to know how parameters work of if, else if, while, and for statements work.
All of these requires parenthesis “( )”, which inside of the parenthesis is where parameters are set that would enable the code dedicated to it. When the condition is set, it outputs a value of true. In Boolean operations, it relates 1 to be true and 0 to be false. So, what this means is that you don’t need to tell the parameter to be equal to 1 to run, you can just simply include the button in it since the button, when pressed, will output 1, which is the same exact thing as true.
Summary: 1 is the same thing as true, which whatever is in the parenthesis will run if it notices an output is true. So, instead of saying “if(button == 1)” which is the same thing as “if(button == true)”, you can just tell it “if(button)”.

1 Like

I have to say I love the name “yeeter” as a motor. :joy:

@Therunner – You got fixes, how did they pan out, everything working fine?