I wanted to double check on my code

Blockquote// VEX V5 C++ Project

#include "vex.h"
using namespace vex;

//#region config_globals
vex::brain      Brain;
vex::motor      FrontLeft(vex::PORT1, vex::gearSetting::ratio18_1, false);
vex::motor      FrontRight(vex::PORT10, vex::gearSetting::ratio18_1, true);
vex::motor      BackLeft(vex::PORT11, vex::gearSetting::ratio18_1, false);
vex::motor      BackRight(vex::PORT20, vex::gearSetting::ratio18_1, true);
vex::controller Controller1(vex::controllerType::primary);
//#endregion config_globals


int main(void) {
    while(1){
        Controller1.Screen.setCursor(1,1);//Displays Front Left Motor Temp & Speed on controller
        Controller1.Screen.print("T:" && FrontLeft.temperature(celsius) && "S:" && FrontLeft.velocity(pct));
        Controller1.Screen.clearLine();
        
        Brain.Screen.setCursor(1,1);//Displays Front Left Motor Temp & Speed on brain
        Brain.Screen.print("T:" && FrontLeft.temperature(celsius) && "S:" && FrontLeft.velocity(pct));
        Brain.Screen.clearLine();
        
        Controller1.Screen.setCursor(1,2);//Displays Front Right Motor Temp & Speed on controller
        Controller1.Screen.print("T:" && FrontRight.temperature(celsius) && "S:" && FrontRight.velocity(pct));
        Controller1.Screen.clearLine();
        
        Brain.Screen.setCursor(1,2);//Displays Front Right Motor Temp & Speed on brain
        Brain.Screen.print("T:" && FrontRight.temperature(celsius) && "S:" && FrontRight.velocity(pct));
        Brain.Screen.clearLine();
        
        Controller1.Screen.setCursor(2,1);//Displays Back Left Motor Temp & Speed on controller
        Controller1.Screen.print("T:" && BackLeft.temperature(celsius) && "S:" && BackLeft.velocity(pct));
        Controller1.Screen.clearLine();
        
        Brain.Screen.setCursor(2,1);//Displays Back Left Motor Temp & Speed on brain
        Brain.Screen.print("T:" && BackLeft.temperature(celsius) && "S:" && BackLeft.velocity(pct));
        Brain.Screen.clearLine();
        
        Controller1.Screen.setCursor(2,2);//Displays Back Right Motor Temp & Speed on controller
        Controller1.Screen.print("T:" && BackRight.temperature(celsius) && "S:" && BackRight.velocity(pct));
        Controller1.Screen.clearLine();
        
        Brain.Screen.setCursor(2,2);//Displays Back Right Motor Temp & Speed on brain
        Brain.Screen.print("T:" && BackRight.temperature(celsius) && "S:" && BackRight.velocity(pct));
        Brain.Screen.clearLine();
        
        if(Controller1.Axis2.value() > 1){//Move Forward
            FrontLeft.spin(forward, 75, vex::velocityUnits(pct));
            FrontRight.spin(forward, 75, vex::velocityUnits(pct));
            BackLeft.spin(forward, 75, vex::velocityUnits(pct));
            BackRight.spin(forward, 75, vex::velocityUnits(pct));
        }
        else if(Controller1.Axis2.value() < -1){//Move Backward
            FrontLeft.spin(forward, 75, vex::velocityUnits(pct));
            FrontRight.spin(forward, 75, vex::velocityUnits(pct));
            BackLeft.spin(forward, 75, vex::velocityUnits(pct));
            BackRight.spin(forward, 75, vex::velocityUnits(pct));
        }
        else if(Controller1.Axis4.value() > 1){//Turn Left
            FrontLeft.spin(reverse, 75, vex::velocityUnits(pct));
            FrontRight.spin(forward, 75, vex::velocityUnits(pct));
            BackLeft.spin(reverse, 75, vex::velocityUnits(pct));
            BackRight.spin(forward, 75, vex::velocityUnits(pct));
        }
        else if(Controller1.Axis4.value() < -1){//Turn Right
            FrontLeft.spin(forward, 75, vex::velocityUnits(pct));
            FrontRight.spin(reverse, 75, vex::velocityUnits(pct));
            BackLeft.spin(forward, 75, vex::velocityUnits(pct));
            BackRight.spin(reverse, 75, vex::velocityUnits(pct));
        }
        else{
            FrontLeft.stop();
            FrontRight.stop();
            BackLeft.stop();
            BackRight.stop();
        }
        vex::sleep(1);
    }
}

What is your program trying to accomplish? If you are just testing if the syntax is correct, you can just build/compile the program.

The first part of the code is supposed to display the temperature and the velocity of all four motors since last year we had an overheating issue.
The second part is the movement controls.
Since I am using a school chromebook I am unable to download the V5 text software and program during school, but recently I’ve had some syntax errors with robot-mesh. I am just checking to see if the syntax is correct. Also this can be used as a reference for anyone that wants to display stuff on the controller as almost all the threads I found on the subject talk about the brian rather than the controller.

What are the error messages that are given by robotmesh when the program is built? Also, in your program, when your are moving backward, all of the motors are set to forward. I would change that to reverse or just make the value of the velocity negative.
I would also recommend that you set your motor velocity based on the position of the joysticks. This allows for greater control of the robot. To do that, simply replace the velocity value to

FrontLeft.spin(forward, Controller1.Axis2.value(), vex::velocityUnits(pct));
1 Like

well robot-mesh isn’t giving me any errors, its after I transfer the code from the mesh to the software on my personal computer. For some reason it wasn’t recognizing the ‘&&’. I also only tested it printing one line on the controller and I don’t know if it’ll print four lines on the controller.

That is because for string concantenation, you would use + rather than &&. && would be a logical operator and only would be useful in a boolean expression.
So, it should look like:

Controller1.Screen.print("T: "  + FrontLeft.temperature(celsius) + "S: " + FrontLeft.velocity(pct));
1 Like

ok, for all this time I thought you can only use the + and - boolean expressions for numbers only.
I didn’t know you could apply it to letters.

I’m going to give a quick lesson on operators and how string concatenation works.
There are three main types of operators: mathematical operators, relational operators, and logical operators.
Mathmatical operators are addition, subtraction, multiplication, division and modulus.

//addition is +
//subtraction is -
//multiplicatoin is *
//division is /
//modulus is % 

For example, if I have the code

int x = 5 * 3 % 2

x would be equal to 1. You would use order of operations as normal and read from left to right.

Relational operators are comparing two values. These would be <, >, <=. >=. ==. !=, or less than, greater than, less than or equal to, greater than or equal to, equals, and not equals respectively, They would return a value of true or false. It should also be noted that when using them, you are creating a simple boolean expression.

The final type of operator is the logical operators. Logical operators essentially combine multiple boolean expressions. The three types of logical operators are !(not), &&(and), and or(||). Not essentially just returns the opposite value, and only returns true if the two boolean expressions its combining is true, and or returns true if one or more of the boolean expressions returns true.

This allows programmers to create very complex if statements that only engage if multiple circumstances are true.
You first evaluate the mathmatical operators, then the relational operators, then the logical. For the logical operators, first do not, then and, then or.
For example:

int x = 8;
int y = 10;
if(!(x - y != 10 / 8 && x * y <= 8 || x != y)){
    Brain.Screen.print("Case is true");
}

In this case, nothing would be outputted, since the 2 doesn’t equal 1(integer division means that only an integer can be returned, meaning that the everything after the decimal gets truncated), 80 isn’t less than or equal to 8. Finally, 8 doesn’t equal 8. So, let’s replace all of the boolean expressions with T for true and F for false.

if(!(T && F || T))

This then simplifies to:

if(!(F || T))

and then to:

if(!(T))

which would then lead to the if statement being false.

Let’s switch to string concatenation. String concatenation is basically when your are combining strings to form one big string. You would use + to achieve this. One you use + in a string concatenation, you are stuck using it for the rest of the expression.

Hopefully, this helped with the terminology and when to use certain operators.

1 Like

Well…you learn something new everyday.
Thank you, I’ll definitely use this later on when I learn to clean up my code a bit better.

Also, I don’t know if you have figured this out yet or not, but the brain only takes 3 lines of text.