Problem with programming mechanism wheels

Hello, i have problem with my code for mechanium wheels, the motors won’t do anything please help.

here is my code

#include "vex.h"

using namespace vex;
brain brain1;
vex::motor ClawMotor = vex::motor(vex::PORT3);

vex::motor LtMotorF = vex::motor(vex::PORT7);
vex::motor RtMotorF = vex::motor(vex::PORT16);
vex::motor LtMotorB = vex::motor(vex::PORT2);
vex::motor RtMotorB = vex::motor(vex::PORT14);

vex::motor Motor1 = vex::motor(vex::PORT6, true);
vex::motor Motor2 = vex::motor(vex::PORT19, true);
vex::controller Controller1 = vex::controller();

motor_group LeftMotor (LtMotorB,LtMotorF);
motor_group RightMotor(RtMotorB,RtMotorF);

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




 RtMotorF.spin(directionType::fwd,( Controller1.Axis3.value() - Controller1.Axis4.value() + Controller1.Axis1.value()), vex::velocityUnits::pct);
 LtMotorF.spin(directionType::fwd, ( Controller1.Axis3.value() + Controller1.Axis4.value() - Controller1.Axis1.value()), vex::velocityUnits::pct);
 RtMotorB.spin(directionType::fwd, ( Controller1.Axis3.value() + Controller1.Axis4.value() + Controller1.Axis1.value()), vex::velocityUnits::pct);
 LtMotorB.spin(directionType::fwd,  ( Controller1.Axis3.value() - Controller1.Axis4.value() - Controller1.Axis1.value()), vex::velocityUnits::pct); 
}

What do you mean they do “nothing”
Do they not spin at all or do they not function the way mechinum wheels are meant to?

I mean the motors don’t spin at all, they sit there and do nothing

Your program begins, initializes all your motors, checks the joystick once, sets the motor outputs once, then exits. You might want to check the joysticks and set the motors’ output more than once.

6 Likes

Put your code in a forever loop so that it is constantly checking the position of the joysticks

1 Like

In English; this means that when the program starts, it understands that the motors are in the specified ports. It then checks the joystick values, but because it’s running through the code so fast, you didn’t have time to move the joysticks, so the brain sees the joystick values as 0.
It only runs through the code once, because there is nothing in the code telling it to keep cycling through. So it reads 0, then never gets to check again.

To fix this, you are going to want to put a while (true) {} loop in there. What this does, is it keeps looping through the code inside the brackets while the condition in parenthesis is correct
(You could also use while (1 == 1) instead, it does the same thing)

This is what it should look like:

#include "vex.h"

using namespace vex;
brain brain1;
vex::motor ClawMotor = vex::motor(vex::PORT3);

vex::motor LtMotorF = vex::motor(vex::PORT7);
vex::motor RtMotorF = vex::motor(vex::PORT16);
vex::motor LtMotorB = vex::motor(vex::PORT2);
vex::motor RtMotorB = vex::motor(vex::PORT14);

vex::motor Motor1 = vex::motor(vex::PORT6, true);
vex::motor Motor2 = vex::motor(vex::PORT19, true);
vex::controller Controller1 = vex::controller();

motor_group LeftMotor (LtMotorB,LtMotorF);
motor_group RightMotor(RtMotorB,RtMotorF);

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

  while (true) {

    RtMotorF.spin(directionType::fwd,( Controller1.Axis3.value() - Controller1.Axis4.value() + 
    Controller1.Axis1.value()), vex::velocityUnits::pct);

    LtMotorF.spin(directionType::fwd, ( Controller1.Axis3.value() + Controller1.Axis4.value() - 
    Controller1.Axis1.value()), vex::velocityUnits::pct);

    RtMotorB.spin(directionType::fwd, ( Controller1.Axis3.value() + Controller1.Axis4.value() + 
    Controller1.Axis1.value()), vex::velocityUnits::pct);

    LtMotorB.spin(directionType::fwd,  ( Controller1.Axis3.value() - Controller1.Axis4.value() - 
    Controller1.Axis1.value()), vex::velocityUnits::pct); 

    wait (20,msec);
  }
}

It’s an easy fix, but also easy to miss.
(This happened to my team our first year)

In the future, if you want to program any more motors, add the code inside of the while loop and it will keep refreshing the outputs until you shut off the program.

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.