Help Compiling VEX V5 C++ in VEX Coding Studio

#1

I am trying to get the following code to compile. I need to make motors on ports 1 & 2 to spin forward with controller axis 3, and a motor on port 3 to spin with axis 1. I want these motors to be reversible(go backwards when the joystick does). My code also reads the temperature of the battery and motors and reports them to the controller, making it rumble when one of them surpasses 75%
Begin Code:
#include “robot-config.h”

int ForwardSpeed = 0;
int LeftRight = 0;
double motor1temp = 0;
double motor2temp = 0;
double motor3temp = 0;
double batterytemp = 0;

int main()
{

getcontroller();
drive();
Controller1.ButtonUp.pressed(diagnosticscheck());

}

int getcontroller()
{
ForwardSpeed = controller.Axis3.value();
LeftRight = controller.axis1.value();
}

int drive()
{
Motor1.spin(directionType::fwd, ForwardSpeed, velocityUnits::rpm);
Motor2.spin(directionType::fwd, ForwardSpeed, velocityUnits::rpm);
Motor3.spin(directionType::fwd, leftRight, velocityUnits::rpm);
}

int diagnosticscheck()
{
motor1temp = Motor1.temperature(percentUnits::pct);
motor2temp = Motor2.temperature(percentUnits::pct);
motor3temp = Motor3.temperature(percentUnits::pct);
batterytemp = Brain.Battery.temperature();

report();

}

int report()
{
Controller1.Screen.clearScreen();
Controller1.Screen.setCursor(1, 1);
Controller1.Screen.print(“Thermal Readings:”);
Controller1.Screen.newLine();
Controller1.Screen.print("Drive Motors: ", motor1temp, " - ", motor2temp);
Controller1.Screen.newLine();
Controller1.Screen.print("Steering Motor: ", motor3temp);
Controller1.Screen.newLine();
Controller1.Screen.print("Battery: ", batterytemp);
Controller1.Screen.newLine();

if (motor1temp > 75)
{
    Controller1.rumble("..");
    Controller1.Screen.print("Motor 1 overheating!");
}
else if (motor2temp > 75)
{
    Controller1.rumble("..");
    Controller1.Screen.print("Motor 2 overheating!");
}
else if (motor3temp > 75)
{
    Controller1.rumble("..");
    Controller1.Screen.print("Motor 3 overheating!");
}
else if (batterytemp > 75)
{
    Controller1.rumble("..");
    Controller1.Screen.print("Battery overheating!");
}

}

int screensetup ()
{
Controller1.Screen.clearScreen();
Controller1.Screen.print(“T-frame drive system online.”);
Controller1.Screen.clearScreen();
}

End Code.

0 Likes

#2

First, you’ll want to initially declare functions you later use, or just write them at the top. You cannot call an undeclared function.

Second, once you’ve corrected this, while it will (lacking other errors, such as where you wrote “controller” instead of “Controller1” as well as capitalization errors in get controller() ) compile, it will fail to run properly. You are not coding event handlers and standard functions differently. Only the event handler will keep running, while the others will stop functioning nearly instantly because they’re not in being repeated. You really want main() to look more like this:

int main()
{
   Controller1.ButtonUp.pressed(diagnosticscheck());
   while(true) {
      getcontroller();
      drive();
   }
}
1 Like