Hey, new programmer for our team etc etc… Started using vex pro and the auto generated code with the robot configuration which was great and super straight forward, eventually adding on top of the auto generated code with some of my own. The problem however, is now that I need to learn autonmous I have no clue how to intergrate the auto generated driver code with an autnomous. All the driver code is in the robot-config.cpp file and not in the main.cpp file where in the compeition template example it has driver code is in the void usercontrol(void) function. Do I suck it up and start from scratch with orginal drive code or is there some way to used the auto generated code with an autnomous?
this is my attempt at moving the auto generated code to the main.pp file compeition template to work with an autonomous example.
im gettiing this error: 1 error generated.
make: *** [vex/mkrules.mk:13: build/src/main.o] Error 1
[error]: make process closed with exit code : 2
/----------------------------------------------------------------------------/
/* /
/ Module: main.cpp /
/ Author: VEX /
/ Created: Thu Sep 26 2019 /
/ Description: Clawbot Competition Template /
/ /
/----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----
#include “vex.h”
using namespace vex;
using signature = vision::signature;
using code = vision::code;
// A global instance of competition
competition Competition;
// define your global instances of motors and other devices here
// A global instance of brain used for printing to the V5 Brain screen
brain Brain;
// VEXcode device constructors
inertial DrivetrainInertial = inertial(PORT15);
motor leftMotorA = motor(PORT2, ratio18_1, false);
motor leftMotorB = motor(PORT20, ratio18_1, true);
motor_group LeftDriveSmart = motor_group(leftMotorA, leftMotorB);
motor rightMotorA = motor(PORT11, ratio18_1, true);
motor rightMotorB = motor(PORT12, ratio18_1, false);
motor_group RightDriveSmart = motor_group(rightMotorA, rightMotorB);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 380, 300, mm, 1);
motor Elevator = motor(PORT1, ratio6_1, false);
motor front_claw = motor(PORT10, ratio18_1, false);
motor rear_claw = motor(PORT13, ratio18_1, false);
motor Lifting_arm = motor(PORT9, ratio36_1, false);
controller Controller1 = controller(primary);
// VEXcode generated functions
// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
// define variables used for controlling motors based on controller inputs
bool Controller1LeftShoulderControlMotorsStopped = true;
bool Controller1RightShoulderControlMotorsStopped = true;
bool Controller1RightDownButtonsControlMotorsStopped = true;
bool Controller1YBButtonsControlMotorsStopped = true;
bool DrivetrainLNeedsToBeStopped_Controller1 = true;
bool DrivetrainRNeedsToBeStopped_Controller1 = true;
/---------------------------------------------------------------------------/
/* 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 V5 has been powered on and /
/ not every time that the robot is disabled. /
/---------------------------------------------------------------------------*/
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Brain.Screen.print(“Device initialization…”);
Brain.Screen.setCursor(2, 1);
// calibrate the drivetrain Inertial
wait(200, msec);
DrivetrainInertial.calibrate();
Brain.Screen.print(“Calibrating Inertial for Drivetrain”);
// wait for the Inertial calibration process to finish
while (DrivetrainInertial.isCalibrating()) {
wait(25, msec);
}
// reset the screen now that the calibration is complete
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1,1);
wait(50, msec);
Brain.Screen.clearScreen();
}
// 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 autonomous(void) {
inertial(PORT15).calibrate();
// waits for the Inertial Sensor to calibrate
while (inertial(PORT15).isCalibrating()) {
wait(100, msec);
}
// Turns the robot to the right
LeftDriveSmart.spin(forward);
RightDriveSmart.spin(reverse);
// Waits until the motor reaches a 90 degree turn and stops the Left and
// Right Motors.
waitUntil((inertial(PORT15).rotation(degrees) >= 90.0));
LeftDriveSmart.stop();
RightDriveSmart.stop();
wait(1, seconds);
}
/---------------------------------------------------------------------------/
/* /
/ 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. /
/---------------------------------------------------------------------------*/
void usercontrol(void) {
// User control code here, inside the loop
// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_function_Controller1() {
// process the controller input every 20 milliseconds
// update the motors based on the input values
//setting the motors to hold instead of coasting
Lifting_arm.setBrake(hold);
front_claw.setBrake(hold);
rear_claw.setBrake(hold);
while(true) {
if(RemoteControlCodeEnabled) {
// calculate the drivetrain motor velocities from the controller joystick axies
// left = Axis3 + Axis1
// right = Axis3 - Axis1
int drivetrainLeftSideSpeed = Controller1.Axis3.position() + Controller1.Axis1.position();
int drivetrainRightSideSpeed = Controller1.Axis3.position() - Controller1.Axis1.position();
// check if the value is inside of the deadband range
if (drivetrainLeftSideSpeed < 5 && drivetrainLeftSideSpeed > -5) {
// check if the left motor has already been stopped
if (DrivetrainLNeedsToBeStopped_Controller1) {
// stop the left drive motor
LeftDriveSmart.stop();
// tell the code that the left motor has been stopped
DrivetrainLNeedsToBeStopped_Controller1 = false;
}
} else {
// reset the toggle so that the deadband code knows to stop the left motor nexttime the input is in the deadband range
DrivetrainLNeedsToBeStopped_Controller1 = true;
}
// check if the value is inside of the deadband range
if (drivetrainRightSideSpeed < 5 && drivetrainRightSideSpeed > -5) {
// check if the right motor has already been stopped
if (DrivetrainRNeedsToBeStopped_Controller1) {
// stop the right drive motor
RightDriveSmart.stop();
// tell the code that the right motor has been stopped
DrivetrainRNeedsToBeStopped_Controller1 = false;
}
} else {
// reset the toggle so that the deadband code knows to stop the right motor next time the input is in the deadband range
DrivetrainRNeedsToBeStopped_Controller1 = true;
}
// only tell the left drive motor to spin if the values are not in the deadband range
if (DrivetrainLNeedsToBeStopped_Controller1) {
LeftDriveSmart.setVelocity(drivetrainLeftSideSpeed, percent);
LeftDriveSmart.spin(forward);
}
// only tell the right drive motor to spin if the values are not in the deadband range
if (DrivetrainRNeedsToBeStopped_Controller1) {
RightDriveSmart.setVelocity(drivetrainRightSideSpeed, percent);
RightDriveSmart.spin(forward);
}
// check the ButtonL1/ButtonL2 status to control front_claw
if (Controller1.ButtonL1.pressing()) {
front_claw.spin(forward);
Controller1LeftShoulderControlMotorsStopped = false;
} else if (Controller1.ButtonL2.pressing()) {
front_claw.spin(reverse);
Controller1LeftShoulderControlMotorsStopped = false;
} else if (!Controller1LeftShoulderControlMotorsStopped) {
front_claw.stop();
// set the toggle so that we don't constantly tell the motor to stop when the buttons are released
Controller1LeftShoulderControlMotorsStopped = true;
}
// check the ButtonR1/ButtonR2 status to control Lifting_arm
if (Controller1.ButtonR1.pressing()) {
Lifting_arm.setVelocity(100, percent);
Lifting_arm.spin(forward);
Controller1RightShoulderControlMotorsStopped = false;
} else if (Controller1.ButtonR2.pressing()) {
Lifting_arm.spin(reverse);
Controller1RightShoulderControlMotorsStopped = false;
} else if (!Controller1RightShoulderControlMotorsStopped) {
Lifting_arm.stop();
// set the toggle so that we don't constantly tell the motor to stop when the buttons are released
Controller1RightShoulderControlMotorsStopped = true;
}
// check the ButtonRight/ButtonDown status to control Elevator
if (Controller1.ButtonRight.pressing()) {
Elevator.spin(forward);
Elevator.setVelocity(100, percent);
Controller1RightDownButtonsControlMotorsStopped = false;
} else if (Controller1.ButtonDown.pressing()) {
Elevator.spin(reverse);
Controller1RightDownButtonsControlMotorsStopped = false;
}else if (Controller1.ButtonUp.pressing()) {
Elevator.stop();
// } else if (!Controller1UpDownButtonsControlMotorsStopped) {
// Elevator.stop();
// set the toggle so that we don't constantly tell the motor to stop when the buttons are released
Controller1RightDownButtonsControlMotorsStopped = true;
}
// check the ButtonY/ButtonB status to control rear_claw
if (Controller1.ButtonY.pressing()) {
rear_claw.spin(forward);
Controller1YBButtonsControlMotorsStopped = false;
} else if (Controller1.ButtonB.pressing()) {
rear_claw.spin(reverse);
Controller1YBButtonsControlMotorsStopped = false;
} else if (!Controller1YBButtonsControlMotorsStopped) {
rear_claw.stop();
// set the toggle so that we don't constantly tell the motor to stop when the buttons are released
Controller1YBButtonsControlMotorsStopped = true;
}
}
// wait before repeating the process
wait(20, msec);
}
return 0;
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}