our code is completely screwed up because we get dumb errors that I don’t know how to solve.
we are now asking for assistance in fixing our code. please help if you can. also here is the code.
// steps below.
//
// 1. You can use the Robot Configuration window to recreate your V5 devices
// - including any motors, sensors, 3-wire devices, and controllers.
//
// 2. All previous code located in main.cpp has now been commented out. You
// will need to migrate this code to the new "int main" structure created
// below and keep in mind any new device names you may have set from the
// Robot Configuration window.
//
// If you would like to go back to your original project, a complete backup
// of your original (pre-upgraded) project was created in a backup folder
// inside of this project's folder.
// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----
using namespace vex;
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
//vexcodeInit();
#include "vex.h"
}
/* */
/* Module: main.cpp */
/* Author: C:\Users\Jennifer */
/* Created: Wed Sep 25 2019 */
/* Description: V5 project */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// ---- END VEXCODE CONFIGURED DEVICES ----
using namespace vex;
// A global instance of vex::brain used for printing to the V5 brain screen
// A global instance of vex::competition
vex::competition competition;
//#include "robot-config.h"
// /*---------------------------------------------------------------------------*/
// /* */
// /* Description:7177b competition program */
// /* */
// /*---------------------------------------------------------------------------*/
//
// //Creates a competition object that allows access to Competition methods.
//
//
// /*----------------------------------------------------------------------------------*/
// /* GLOBAL DEFINITION AREA */
// /*----------------------------------------------------------------------------------*/
//
// // storage for our auton selection
// int autonomousSelection = -1;
// double angleTolerance = 3;
//
// /*----------------------------------------------------------------------------------*/
// /* James Pearman autoselect functions and definitions. These are modified for Walsh */
// /*----------------------------------------------------------------------------------*/
//
// /*----------------------------------------------------------------------------------*/
// /* collect data for on screen button and include off and on color feedback for */
// /* button prc - instead of radio approach with one button on or off at a time, each */
// /* button has a state. ie shootPreload may be low yellow and high yellow when on. */
// /*----------------------------------------------------------------------------------*/
//
typedef struct _button {
int xpos;
int ypos;
int width;
int height;
bool state;
vex::color offColor;
vex::color onColor;
const char *label;
} button;
// /*----------------------------------------------------------------------------------*/
// /* Button array definition for each software button. The purpose of each button data*/
// /* structure is defined above. THe array size can be extended, so you can have many */
// /* buttons as you wish as long as it fits on the screen */
// /*----------------------------------------------------------------------------------*/
button buttons[] = {
{ 30, 30, 60, 60, false, 0xE00000, 0x0000E0, "Alliance" }, // Defines the ally (blue or red)
{ 150, 30, 60, 60, false, 0x303030, 0xD0D0D0, "Front" }, // Defines the starting tile Black= near the net/flags and white = the far tile
{ 270, 30, 60, 60, false, 0x303030, 0xF700FF, "" }, // this does nothing
{ 390, 30, 60, 60, false, 0x303030, 0xDDDD00, "" }, // this does nothing
{ 30, 150, 60, 60, false, 0x404040, 0xC0C0C0, "Skills" }, //sets the program into skills automaticaly
{ 150, 150, 60, 60, false, 0x404040, 0xC0C0C0, "" }, //this does nothing
{ 270, 150, 60, 60, false, 0x404040, 0xC0C0C0, "" }, //this does nothing
{ 390, 150, 60, 60, false, 0x404040, 0xC0C0C0, "" } //this does nothing
};
// /*----------------------------------------------------------------------------------*/
// /* forward reference */
// /*----------------------------------------------------------------------------------*/
//
void displayButtonControls( int index, bool pressed );
//
// /*----------------------------------------------------------------------------------*/
// /** @brief Check if touch is inside button */
// /*----------------------------------------------------------------------------------*/
int
findButton( int16_t xpos, int16_t ypos ) {
int nButtons = sizeof(buttons) / sizeof(button);
for( int index=0;index < nButtons;index++) {
button *pButton = &buttons[ index ];
if( xpos < pButton->xpos || xpos > (pButton->xpos + pButton->width) )
continue;
if( ypos < pButton->ypos || ypos > (pButton->ypos + pButton->height) )
continue;
return(index);
}
return (-1);
}
// /*----------------------------------------------------------------------------------*/
// /** @brief Init button states */
// /*---------------------------------------------------------------------------------*/
// void
// initButtons() {
// int nButtons = sizeof(buttons) / sizeof(button);
//
// for( int index=0;index < nButtons;index++) {
// buttons[index].state = false;
// }
// }
//
// /*----------------------------------------------------------------------------------*/
// /** @brief Screen has been touched */
// /*----------------------------------------------------------------------------------*/
void
userTouchCallbackPressed() {
int index;
int xpos = Brain1.Screen.xPosition();
int ypos = Brain1.Screen.yPosition();
if( (index = findButton( xpos, ypos )) >= 0 ) {
displayButtonControls( index, true );
}
}
/*----------------------------------------------------------------------------------*/
// /** @brief Screen has been (un)touched */
// /*----------------------------------------------------------------------------------*/
void
userTouchCallbackReleased() {
int index;
int xpos = Brain1.Screen.xPosition();
int ypos = Brain1.Screen.yPosition();
if( (index = findButton( xpos, ypos )) >= 0 ) {
clear (button to false, ie. unselected);
initButtons();
// now set this one as true
if( buttons[index].state == true) {
buttons[index].state = false; }
else {
buttons[index].state = true;}
// save as auton selection
autonomousSelection = index;
displayButtonControls( index, false );
}
}
/*----------------------------------------------------------------------------------*/
/** @brief Draw all buttons */
/*----------------------------------------------------------------------------------*/
void
displayButtonControls( int index, bool pressed ) {
vex::color c;
Brain1.Screen.setPenColor( vex::color(0xe0e0e0) );
for(int i=0;i<sizeof(buttons)/sizeof(button);i++) {
if( buttons[i].state )
c = buttons[i].onColor;
else
c = buttons[i].offColor;
Brain1.Screen.setFillColor( c );
// button fill
if( i == index && pressed == true ) {
Brain1.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height, c );
}
else
Brain1.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height );
// outline
Brain1.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height, vex::color::transparent );
// draw label
if( buttons[i].label != NULL )
Brain1.Screen.printAt( buttons[i].xpos + 8, buttons[i].ypos + buttons[i].height - 8, buttons[i].label );
}
}
// /*----------------------------------------------------------------------------------*/
// /* BUTTON DRAWING IS COMPLETE */
// /*----------------------------------------------------------------------------------*/
//
//
// /*----------------------------------------------------------------------------------*/
// /* ITERATION HAPPENS: TEAM FUNCTIONS */
// /*----------------------------------------------------------------------------------*/
//
//
void drive(int Power, int Rotations1, int Rotations2) {
Drivetrainleftback.rotateFor(Rotations1,rotationUnits::deg,Power,velocityUnits::pct,false);
Drivetrainrightback.rotateFor(Rotations2,rotationUnits::deg,Power,velocityUnits::pct,false);
Drivetrainrightfront.rotateFor(Rotations2,rotationUnits::deg,Power,velocityUnits::pct,false);
Drivetrainleftfront.rotateFor(Rotations1,rotationUnits::deg,Power,velocityUnits::pct);
}
void move(int leftPower, int rightPower){
Drivetrainrightback.spin(vex::directionType::fwd, rightPower, vex::velocityUnits::pct); //(Axis3+Axis4)/2
Drivetrainleftback.spin(vex::directionType::fwd, leftPower, vex::velocityUnits::pct); //(Axis3+Axis4)/2
Drivetrainrightfront.spin(vex::directionType::fwd, rightPower, vex::velocityUnits::pct); //(Axis3+Axis4)/2
Drivetrainleftfront.spin(vex::directionType::fwd, leftPower, vex::velocityUnits::pct); //(Axis3+Axis4)/2
}
// Dumping Functions
void dumper(int Power, int Rotations) {
Dumper.rotateFor(Rotations,rotationUnits::deg,Power,velocityUnits::pct);
}
// // Claw Functions
void Claw(int Power, int Rotations) {
LeftClaw.rotateFor(Rotations,rotationUnits::deg,Power,velocityUnits::pct);
RightClaw.rotateFor(Rotations,rotationUnits::deg,Power,velocityUnits::pct);
}
// Lift Functions
void lift(int Power, int Rotations) {
Lift.rotateFor(Rotations,rotationUnits::deg,Power,velocityUnits::pct);
}
int getAngleDifference(double desiredAngle,double currentAngle) {
int angleDifference = desiredAngle - currentAngle;
angleDifference = angleDifference % 360;
if (angleDifference > 180) {
angleDifference = angleDifference - 360;
}
return angleDifference;
}
void turn(int power, double angle){
int angleDifference = getAngleDifference(angle,Gyro1.value(rotationUnits::deg));
//while ((Gyro1.value(rotationUnits::deg) <= angle - angleTolerance) || (Gyro1.value(rotationUnits::deg) >= angle + angleTolerance)){
while ((angleDifference <= - angleTolerance) || (angleDifference >= angleTolerance)){
if (angleDifference < 0){
move(-power, power);
}
else if (angleDifference > 0){
move(power, -power);
}
else {
move(0,0);
}
//Brain.Screen.clearScreen();
//Brain.Screen.printAt(1,40,"rotation: %f degrees", Gyro1.value(rotationUnits::deg));
//Brain.Screen.printAt(1,40,"rotation: %d degrees", angleDifference);
//vex::task::sleep(100);
angleDifference = getAngleDifference(angle,Gyro1.value(rotationUnits::deg));
}
move(0,0);
}
void Skills(){
Brain1.Screen.print("Subscribe To Pewdiepie");
}
void Red_Front(){
Brain1.Screen.print("Subscribe To Pewdiepie");
}
void Blue_Front(){
Brain1.Screen.print("Subscribe To Pewdiepie");
}
void Red_Back(){
Brain1.Screen.print("Subscribe To Pewdiepie");
turn(90,90);
turn(90,90);
}
void Blue_Back(){
Brain1.Screen.print("Subscribe To Pewdiepie");
}
double getSlope(double x1, double x2, int y1, int y2) {
return (y2 - y1)/(x2 - x1);
}
double getSpeed(double m, double x, double x1, int y1) {
return (m*(x-x1)+y1);
}
// /*---------------------------------------------------------------------------*/
// /* 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( void ) {
// 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 ) {
// ..........................................................................
/*----------------------------------------------------------------------------------*/
/* NEW BUTTON AUTON */
/* */
/* The next section sets the main variables for the buttons that will be chosen */
/* */
/*----------------------------------------------------------------------------------*/
/* initialize capabilities from buttons */
bool allianceBlue = buttons[0].state;
bool startTileFar = buttons[1].state;
bool startskills = buttons[4].state;
/* bool doPark = buttons[2].state;
bool shootPreload = buttons[3].state;*/
/*----------------------------------------------------------------------------------*/
/* The main section of the code based on what selections where chosen */
/*----------------------------------------------------------------------------------*/
if(startskills){
Skills();
} else {
if(startTileFar) {
if(allianceBlue){
Blue_Front();
} else {
Red_Front();
}
} else {
if(allianceBlue){
Blue_Back();
} else {
Red_Back();
}
} // End of StartTileFar
} //End of Start Skills
} // End of Auton
/*int howMany = 1250;
Drivetrainleftfront.startRotateFor (howMany, rotations);
Drivetrainleftback.startRotateFor (howMany, rotations);
Drivetrainrightfront.startRotateFor (howMany, rotations);
Drivetrainrightback.startRotateFor (howMany, rotations);
vex::task::sleep(1000);
howMany = -1250;
Drivetrainleftback.startRotateFor(howMany, rotations);
Drivetrainleftfront.startRotateFor(howMany, rotations);
Drivetrainrightback.startRotateFor(howMany, rotations);
Drivetrainrightfront.startRotateFor(howMany, rotations); */
// ..........................................................................
/*----------------------------------------------------------------------------*/
/* */
/* 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 ) {
//Use these variables to set the speed of the lift.
int liftSpeedPCT = 100;
//Use these variables to set the speed of the lift.
int ClawSpeedPCT = 100;
//Use these variables to set the speed of the Dumper.
// the int variables are the speed of the dumper the double sets the position that it slows down.
int Dumper1SpeedPCT = 30;
int Dumper2SpeedPCT = 20;
int Dumper3SpeedPCT = 10;
int Dumper4SpeedPCT = 0;
int Dumper69overrideSpeedPCT = 20;
double Dumper1Rotations = 0;
double Dumper2Rotations = 5;
double Dumper3Rotations = 10;
double Dumper4Rotations = 15;
Brain.setTimer(10,timeUnits::sec); // User control code here, inside the loop
while (1){
//Begining of driver control
//Tank Drive two joy sticks
//this is the drive function
//move(Controller1.Axis3.value(), Controller1.Axis2.value());
//Lift
if(Controller1.ButtonR1.pressing()) {
Lift.spin(directionType::fwd, liftSpeedPCT, velocityUnits::pct);
}
else if (Controller1.ButtonR2.pressing()) {
Lift.spin(directionType::rev, liftSpeedPCT, velocityUnits::pct);
}
else {
Lift.stop(brakeType::hold);
}
//Claw
//the if statements pulls the cubes in the else if spits them out
if(Controller1.ButtonL1.pressing()) {
LeftClaw.spin(directionType::fwd, ClawSpeedPCT, velocityUnits::pct);
RightClaw.spin(directionType::fwd, ClawSpeedPCT, velocityUnits::pct);
}
else if (Controller1.ButtonL2.pressing()) {
LeftClaw.spin(directionType::rev, ClawSpeedPCT, velocityUnits::pct);
RightClaw.spin(directionType::rev, ClawSpeedPCT, velocityUnits::pct);
}
else {
LeftClaw.stop(brakeType::brake);
RightClaw.stop(brakeType::brake);
}
//Dumper, the varibales change the speed of the Dumper based on its position
if(Controller1.ButtonB.pressing()) {
double measuredRotations = Dumper.rotation (rotationUnits::rev);
double slope = 0;
double speed = 0;
if(measuredRotations < Dumper1Rotations ){
Dumper.spin(directionType::fwd, Dumper1SpeedPCT, velocityUnits::pct);
}
else if (measuredRotations < Dumper2Rotations ){
slope = getSlope (Dumper1Rotations,Dumper2Rotations,Dumper1SpeedPCT,Dumper2SpeedPCT);
speed = getSpeed (slope,measuredRotations,Dumper1Rotations,Dumper1SpeedPCT);
//Brain.Screen.clearLine();
//Brain.Screen.print(speed);
Dumper.spin(directionType::fwd, speed, velocityUnits::pct);
}
else if (measuredRotations < Dumper3Rotations ){
slope = getSlope (Dumper2Rotations,Dumper3Rotations,Dumper2SpeedPCT,Dumper3SpeedPCT);
speed = getSpeed (slope,measuredRotations,Dumper2Rotations,Dumper2SpeedPCT);
//Brain.Screen.print(slope);
Dumper.spin(directionType::fwd, speed, velocityUnits::pct);
}
else if (measuredRotations < Dumper4Rotations ){
slope = getSlope (Dumper3Rotations,Dumper4Rotations,Dumper3SpeedPCT,Dumper4SpeedPCT);
speed = getSpeed (slope,measuredRotations,Dumper3Rotations,Dumper3SpeedPCT);
//Brain.Screen.print(slope);
Dumper.spin(directionType::fwd, speed, velocityUnits::pct);
}
else{
Dumper.spin(directionType::fwd, Dumper4SpeedPCT, velocityUnits::pct);
}
}
else if(Controller1.ButtonA.pressing()) {
Dumper.spin(directionType::rev, Dumper2SpeedPCT, velocityUnits::pct);
}
//this is the manual override
else if(Controller1.ButtonX.pressing()) {
Dumper.spin(directionType::fwd, Dumper69overrideSpeedPCT,velocityUnits::pct);
}
else if (Controller1.ButtonY.pressing()) {
Dumper.spin(directionType::rev, Dumper69overrideSpeedPCT,velocityUnits::pct);
}
else {
Dumper.stop(brakeType::brake);
}
if(Controller1.ButtonUp.pressing()) {
move(Controller1.Axis3.value()/2, Controller1.Axis2.value()/2);
}
else if (Controller1.ButtonDown.pressing()) {
move(Controller1.Axis3.value()*2, Controller1.Axis2.value()*2);
}
else{
move(Controller1.Axis3.value(), Controller1.Axis2.value());
}
vex::task::sleep(20); //Sleep the task for a short amount of time to prevent wasted resources.
}
}
//
// Main will set up the competition functions and callbacks.
//int main{
//Drivetrainleftfront.spin(directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2,vex::velocityUnits::pct); //(Axis3+Axis4)/2;
//Drivetrainleftrear.spin(directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2,vex::velocityUnits::pct); //(Axis3+Axis4)/2;
//Drivetrainrightfront.spin(directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2,vex::velocityUnits::pct); //(Axis3-Axis4)/2;
//Drivetrainrightrear.spin(directionType::fwd, (Controller1.Axis3.value() + Controller1.Axis4.value())/2,vex::velocityUnits::pct); //(Axis-Axis4)/2;
//vex::task::sleep (20);
//}
//Run the pre-autonomous function.
pre_auton();
//Set up callbacks for autonomous and driver control periods.
competition.autonomous( autonomous );
competition.drivercontrol( usercontrol );
// register events for button selection
brain.Screen.pressed( userTouchCallbackPressed );
brain.Screen.released( userTouchCallbackReleased );
// make nice background
brain.Screen.setFillColor( vex::color(0x404040) );
brain.Screen.setPenColor( vex::color(0x404040) );
brain.Screen.drawRectangle( 0, 0, 480, 120 );
brain.Screen.setFillColor( vex::color(0x808080) );
brain.Screen.setPenColor( vex::color(0x808080) );
brain.Screen.drawRectangle( 0, 120, 480, 120 );
// initial display
displayButtonControls( 0, false );
while(1) {
// Allow other tasks to run
if( !Competition.isEnabled() )
Brain1.Screen.setFont(vex::fontType::mono40);
Brain1.Screen.setFillColor( vex::color(0xFFFFFF) );
Brain1.Screen.setPenColor( vex::color(0xc11f27));
Brain1.Screen.printAt( 0, 135, " Iteration Happens " );
vex::this_thread::sleep_for(10);
}
}