VexCode v5 pro refusing to run more than 2 spin commands

It is within my first two weeks of programming with vexcode and I would appreciate any help. I have everything working properly in other tests, this is a logic error. When I run the two methods in the main class or run the four lines of code individually I have the same problem, I just put them in methods to read easier. It will only turn left and right but won’t move forward and backwards. I’m not sure if there is a limit to spin commands or if there is an error in the code itself, thanks.

void forwBack(){
RightFrontMotor.spin(fwd, -(Controller1.Axis3.position()), pct);
LeftFrontMotor.spin(fwd, (Controller1.Axis3.position()), pct);
}
void leftRight(){
LeftFrontMotor.spin(fwd, Controller1.Axis4.position(), pct);
RightFrontMotor.spin(fwd, Controller1.Axis4.position(), pct);
}

int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

while(1){
forwBack();
leftRight();

vex::task::sleep(100);

}
}

Is this all your code? (if not share it please) If this is all your code you are missing a ton of stuff to make it work like if statements, forever loops, and the competition template. Here’s some helpers:

Also please use``` around your code to format it

Ok thank you!

There is much more, here is all of the code in my main. There is more in the robot-config and vex-h, it was all premade though when I loaded the file and connect the motor ports and such. Also, I don’t type in forums very much, so I hope this is what you meant by the `s.

Main:
#include "vex.h"
using namespace vex;

vex::motor RightFrontMotor = vex::motor(vex::PORT1);
vex::motor LeftFrontMotor = vex::motor(vex::PORT2);

void forwBack(){
RightFrontMotor.spin(fwd, -(Controller1.Axis3.position()), pct);
LeftFrontMotor.spin(fwd, (Controller1.Axis3.position()), pct);
}
void leftRight(){
LeftFrontMotor.spin(fwd, Controller1.Axis4.position(), pct);
RightFrontMotor.spin(fwd, Controller1.Axis4.position(), pct);
}

int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

while(1){
forwBack();
leftRight();

`vex::task::sleep(100);`

}
}

Sorry that the spacing is garbo, it won’t let me tab.

Here is the vex-h, I am unaware of what most of this is and I haven’t edited it:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "v5.h"
#include "v5_vcs.h"

#include "robot-config.h"

#define waitUntil(condition)
do {
wait(5, msec);
} while (!(condition))

#define repeat(iterations)
for (int iterator = 0; iterator < iterations; iterator++)

Here is the robot-config.h(Same as vex-h, haven’t edited):

using namespace vex;
extern brain Brain;
// VEXcode devices

extern motor frontRight;
extern motor frontLeft;
extern motor backRight;
extern motor backLeft;
extern controller Controller1;

void vexcodeInit( void );

Finally here is the robot-config.cpp

#include "vex.h"
using namespace vex;

using signature = vision::signature;
using code = vision::code;
brain Brain;

motor frontRight = motor(PORT1, ratio18_1, false);
motor frontLeft = motor(PORT2, ratio18_1, false);
motor backRight = motor(PORT3, ratio18_1, false);
motor backLeft = motor(PORT4, ratio18_1, false);
controller Controller1 = controller(primary);

bool RemoteControlCodeEnabled = true;

void vexcodeInit( void ) {
// nothing to initialize
}

Sorry for not having enough info in my first post, thank you for the help.

1 Like

What do you expect this code to do?

Walking through it, start from main which is the entry point. After calling the vexcodeInit function, you go into a while loop that first calls forwBack(); and then leftRight(); and then waits 100 msec.

In forwBack() you read the value of the joystick (Axis3) and tell the motors to spin in opposite directions at the speed from the joystick. Is that what you want to happen? Are you doing anything with the joystick while running the program?

2 Likes

This is a 2 motor 4 wheeled basic square base. I have been using code that made the left joystick control the left front wheel motor and the right stick the right front motor. I felt that this was not very user friendly so I was attempting to change it so that the left stick controls all turning and moving so the other stick could be used for other things. the leftRight(); method uses the .spin method for the motor class and turn it left and right with the two front wheels. The forwBack(); does the same thing but just forwards and backwards.

Main:
#include "vex.h"
using namespace vex;

vex::motor RightFrontMotor = vex::motor(vex::PORT1);
vex::motor LeftFrontMotor = vex::motor(vex::PORT2);

void forwBack(){
RightFrontMotor.spin(fwd, -(Controller1.Axis3.position()), pct);
LeftFrontMotor.spin(fwd, (Controller1.Axis3.position()), pct);
}
void leftRight(){
LeftFrontMotor.spin(fwd, Controller1.Axis4.position(), pct);
RightFrontMotor.spin(fwd, Controller1.Axis4.position(), pct);
}

int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

while(1){
forwBack();
leftRight();

`vex::task::sleep(100);`
}
}

//that the spacing is garbo, it won’t let me tab.

//Here is the vex-h, I am unaware of what most of this is and I haven’t edited it:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "v5.h"
#include "v5_vcs.h"

#include "robot-config.h"

#define waitUntil(condition)
do {
wait(5, msec);
} while (!(condition))

#define repeat(iterations)
for (int iterator = 0; iterator < iterations; iterator++)

//Here is the robot-config.h(Same as vex-h, haven’t edited):

using namespace vex;
extern brain Brain;
// VEXcode devices

extern motor frontRight;
extern motor frontLeft;
extern motor backRight;
extern motor backLeft;
extern controller Controller1;

void vexcodeInit( void );

Finally here is the robot-config.cpp

#include "vex.h"
using namespace vex;

using signature = vision::signature;
using code = vision::code;
brain Brain;

motor frontRight = motor(PORT1, ratio18_1, false);
motor frontLeft = motor(PORT2, ratio18_1, false);
motor backRight = motor(PORT3, ratio18_1, false);
motor backLeft = motor(PORT4, ratio18_1, false);
controller Controller1 = controller(primary);

bool RemoteControlCodeEnabled = true;

void vexcodeInit( void ) {
// nothing to initialize
}

(Formatted for Readability. @Ferpile, you can do this by using 3 backticks: ``` around your code.)

4 Likes

the two functions compete each other and may cause problem.

2 Likes

So, you could use something like this, which takes the two joystick positions and adds or subtracts them, which depends on the side of the robot that the motor is on, to give you your drive speed.

void(drive){ 
     RightFrontMotor.spin(fwd, (Controller1.Axis3.position()-Controller1.Axis4.position()), pct);
     LeftFrontMotor.spin(fwd, (Controller1.Axis3.position()+Controller1.Axis4.position()), pct);
}
3 Likes

I believe this isn’t working because leftRight is being called immediately after forwBack and overriding it. This would cause the forwBack to never work.

are you sure about this?

I think so, but I think @insert_code’s solution would work best.

Thank you so much @insert_code. Working like a charm!