I used the code above and used the names in the code. However, the following errors still appeared:
Here’s my code. Can anyone tell me what’s wrong? Thanks in advance!
Robot Configuration
#include "vex.h"
using namespace vex;
using signature = vision::signature;
using code = vision::code;
// A global instance of brain used for printing to the V5 Brain screen
brain Brain;
// VEXcode device constructors
motor LeftTop = motor(PORT10, ratio18_1, true);
motor RightTop = motor(PORT20, ratio18_1, false);
motor LeftBottom = motor(PORT6, ratio18_1, true);
motor RightBottom = motor(PORT16, ratio18_1, false);
motor Motor19 = motor(PORT19, ratio36_1, false);
motor Motor9 = motor(PORT9, ratio36_1, true);
motor Snapper = motor(PORT11, ratio18_1, false);
motor_group LeftSide = motor_group(LeftTop, LeftBottom);
motor_group RightSide = motor_group(RightTop, RightBottom);
motor_group Lift = motor_group(Motor9, Motor19);
controller Controller1 = controller(primary);
// VEXcode generated functions
/**
* Used to initialize code/tasks/devices added using tools in VEXcode Text.
*
* This should be called at the start of your int main function.
*/
void vexcodeInit( void ) {
// nothing to initialize
}
Actual Driver Control Code
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// LeftTop motor 10
// RightTop motor 20
// LeftBottom motor 6
// RightBottom motor 16
// Motor19 motor 19
// Motor9 motor 9
// Snapper motor 11
// Controller1 controller
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
// define your global instances of motors and other devices here
/*---------------------------------------------------------------------------*/
/* 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();
// 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) {
// ..........................................................................
// Insert autonomous user code here.
// ..........................................................................
}
/*---------------------------------------------------------------------------*/
/* */
/* 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
while (1) {
// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................
Lift.setVelocity(50, percent);
Snapper.setVelocity(100, percent);
int leftMotorSpeed = Controller1.Axis3.position();
// Get the velocity percentage of the right motor. (Axis2)
int rightMotorSpeed = Controller1.Axis2.position();
// Set the speed of the left motor. If the value is less than the deadband,
// set it to zero.
if (abs(leftMotorSpeed) < 10) {
// Set the speed to zero.
LeftSide.setVelocity(0, percent);
} else {
// Set the speed to leftMotorSpeed
LeftSide.setVelocity(leftMotorSpeed, percent);
}
// Set the speed of the right motor. If the value is less than the deadband,
// set it to zero.
if (abs(rightMotorSpeed) < 10) {
// Set the speed to zero
RightSide.setVelocity(0, percent);
} else {
// Set the speed to rightMotorSpeed
RightSide.setVelocity(rightMotorSpeed, percent);
}
// Spin both motors in the forward direction.
LeftSide.spin(forward);
RightSide.spin(forward);
if(Controller1.ButtonL1.pressing()) {
Lift.spin(forward);
}
else if (Controller1.ButtonL2.pressing()) {
Lift.spin(reverse);
}
else {
Lift.stop(hold);
}
if(Controller1.ButtonR1.pressing()) {
Snapper.spin(forward);
}
else if (Controller1.ButtonR2.pressing()) {
Snapper.spin(reverse);
}
else {
Snapper.stop(hold);
}
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
}
//
// 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);
}
}