Will this code work?


#1

This the vex C++ code for our robot. It has four autonomous programs that will be changed through changing a variable on the brain screen but I don’t know how to make that yet. It also has a driver program with 8 motors, 4 drive, 1 lift, 1 cap flipper, 1 catapult, and 1 ball intake. The drive is on one joystick with forward and back controlling forward and back movement and left to right controlling turning. Here’s the code.

#include “robot-config.h”

int main(){

pre_auton();

auton = none
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);

}
void::competition

void autonomous(void){
if(auton == none){
vex::task::sleep(100);
}
if(auton == redfar){
Catapult.rotateFor(3,rotationUnits::fwd);
RightDrive.startRotateFor(10,rotationUnits::rev);
LeftDrive.rotateFor(10,rotationUnits::rev);
RightDrive.startRotateFor(13,rotationUnits::fwd);
LeftDrive.rotateFor(13,rotationUnits::fwd);
RightDrive.startRotateFor(4,rotationUnits::fwd);
LeftDrive.rotateFor(4,rotationUnits::rev);
RightDrive.startRotateFor(8,rotationUnits::fwd);
LeftDrive.rotateFor(8,rotationUnits::fwd);
}
if(auton == redfront){
Catapult.rotateFor(3,rotationUnits::fwd);
RightDrive.startRotateFor(2,rotationUnits::fwd);
LeftDrive.rotateFor(2,rotationUnits::rev);
RightDrive.startRotateFor(8,rotationUnits::fwd);
LeftDrive.rotateFor(8,rotationUnits::fwd);
Lift.rotateFor(0.5,rotationUnits::fwd);
LeftDrive.startRotateFor(4,rotationUnits::fwd);
RightDrive.rotateFor(4,rotationUnits::rev);
RightDrive.startRotateFor(4,rotationUnits::fwd);
LeftDrive.rotateFor(4,rotationUnits::fwd);
Lift.rotateFor(6,rotationUnits::fwd);
LeftDrive.startRotateFor(2,rotationUnits::fwd);
RightDrive.rotateFor(2,rotationUnits::fwd);
Lift.rotateFor(1,rotationUnits::rev);
LeftDrive.startRotateFor(2,rotationUnits::rev);
RightDrive.rotateFor(2,rotationUnits::rev);
}
if(auton == bluefar){
Catapult.rotateFor(3,rotationUnits::fwd);
RightDrive.startRotateFor(10,rotationUnits::rev);
LeftDrive.rotateFor(10,rotationUnits::rev);
RightDrive.startRotateFor(13,rotationUnits::fwd);
LeftDrive.rotateFor(13,rotationUnits::fwd);
RightDrive.startRotateFor(4,rotationUnits::fwd);
LeftDrive.rotateFor(4,rotationUnits::rev);
RightDrive.startRotateFor(8,rotationUnits::rev);
LeftDrive.rotateFor(8,rotationUnits::rev);
}
if(auton == bluefront){
Catapult.rotateFor(3,rotationUnits::fwd);
RightDrive.startRotateFor(2,rotationUnits::rev);
LeftDrive.rotateFor(2,rotationUnits::fwd);
RightDrive.startRotateFor(8,rotationUnits::fwd);
LeftDrive.rotateFor(8,rotationUnits::fwd);
Lift.rotateFor(0.5,rotationUnits::fwd);
LeftDrive.startRotateFor(4,rotationUnits::rev);
RightDrive.rotateFor(4,rotationUnits::fwd);
Lift.rotateFor(6,rotationUnits::fwd);
LeftDrive.startRotateFor(2,rotationUnits::fwd);
RightDrive.rotateFor(2,rotationUnits::fwd);
Lift.rotateFor(1,rotationUnits::rev);
LeftDrive.startRotateFor(2,rotationUnits::rev);
RightDrive.rotateFor(2,rotationUnits::rev);
}
}

void usercontrol()void{
while (1){
RightDrive.spin(vex::directionType::fwd,Controller1.axis2.value()vex::velocityUnits::pct);
LeftDrive.spin(vex::directionType::fwd,Controller1,axis2.value()vex::velocityUnits::pct);
RightDrive.spin(vex::directionType::rev,Controller,axis4.value()vex::velocityUnits::pct);
LeftDrive.spin(vex::directionType::fwd,Controller,axis4.value()vex::velocityUnits::pct);

if(Controller1.ButtonL1.pressing()){
Lift.spin(directionType::fwd,200,vex::velocityUnits::pct);
}
else if(Controller1.ButtonL2.pressing()){
Lift.spin(vex::directionType::rev,200,vex::velocityUnits::pct);
}
else{
Lift.stop(vex::brakeType::brake);
}
if(Controller1.ButtonUp.pressing()){
Spinner.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
}
else if(Controller1.ButtonDown.pressing()){
Spinner.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
}
else{
Spinner.stop(vex::brakeType::brake);
}
if(Controller1.ButtonR1.pressing()){
Catapult.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
}
else{
Catapult.stop(vex::brakeType::brake);
}
if(Controller1.ButtonX.pressing()){
BallIntake.spin(vex::directionType::fwd,200,vex::velocityUnits::pct);
}
else if(Controller1.ButtonB.pressing()){
BallIntake.spin(vex::directionType::rev,200,vex::velocityUnits::pct);
}
else{
BallIntake.stop(vex::brakeType::brake);
}
vex::task::sleep(20);
}
}


#2

Moved into the VCS channel (from ROBOTC tech support) as this is not ROBOTC code.


#3

Did you define “auton” and all its possible values inside robot-config.h?

That second “void” should be in the parentheses.

You’ve got two reals problem here and one behavioral problem that isn’t a coding problem. Consider RightDrive. The brain tries to do the following:

spin it at Controller1.axis.value()
no, spin it at Controller.axis4.value () <— Note, you should have had “.” instead of “,” after “Controller”
no, spin it at Controller1.axis.value()
no, spin it at Controller.axis4.value ()
etc., in rapid succession.

Also, there is no way to turn left. Controller1 can only try to drive forward. Controller can only try to turn right. It’s likely to be very twitchy with either of those. This is the behavioral problem that isn’t a coding problem. Do you really want one controller to only drive forward and one controller to only turn right?


#4

[Not OP] Of course! They’re coding for a sister team they’re trying to sabotage! :slight_smile:
[Not really. Please don’t take literally or as an idea.]