Port on brain, some functions not working

Port 1 on our V5 brain works fine in every aspect we can tell except that we can’t control the direction of a motor when connected to it. When we change the direction of the motor in its declaration (with the true/false flag in the reverse parameter) it just doesn’t change the direction. Same problem exists with other motors that we connect to Port 1. And the problem goes away when we move motors to any other port. We can, however, successfully change the direction of the wheel in a port 1 motor with the spin command. But of course, this means any programming must be done in reverse of the direction we actually want .

When we use the interface on the brain to look at the motor, when connected to Port 1, we can increment / decrement the values and the wheel turns in the correct directions.

Has anyone else had a port problem where the direction of the motor was the only thing that wouldn’t work on a port through programming? Any ideas for fixing this short of replacing the brain?

Is the light flashing on the port where the motor is located? If so it could be broken/a burned port from ESD

sounds much more like a programming problem than an issue with the brain. The ports either works, or it doesn’t, not really anything in between.
What are you using for programming ? can you post a small example project that demonstrates the issue ?

11 Likes

The light on the port is solid. In every respect, the port seems fine, except for the direction problem. We have dealt with burned out ports in the past and this does indeed seem different.

We are using Vexcode Text and here are the relevant lines of the code we are using:

From robot-config.cpp:
motor LeftFrontDriveMotor (PORT1, ratio18_1,false);
false is correct for the orientation of the motor. We tried changing false to true but it still moves in the same direction as when it was false.

From main.cpp:
LeftFrontDriveMotor.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
Just a simple spin command. This makes the wheel attached to the motor spin in reverse; the only way we can make the wheel spin forward is to change the direction to rev.

Are you sure that your program is downloading properly?
I have had more issues like this than I would care to admit from simply not building the program before downloading, or just downloading to a different port on the brain.
I’d recommend checking for any way that the download could have failed, as I agree with jpearman that this seems a bit odd.

1 Like

Could you please post your code?
:slight_smile:

3 Likes

Yes, we can’t really help you unless we are able to see the problematic code.

Sorry, I thought we had already included the code that would be needed. Here is what we have been using for testing. In the code below, the problem is on Port 1 (LeftFrontDriveMotor).

Here is the code from main.cpp.

#include “vex.h”
#include “robot-config.h”

using namespace vex;

competition Competiton;

void leftDrive() {
LeftFrontDriveMotor.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
LeftBackDriveMotor.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
}

void pre_auton( void ) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
}

void autonomous( void ) {

}

void usercontrol( void ) {
while(true) {
Controller1.Axis3.changed(leftDrive);
}
}

int main() {
pre_auton();

Competiton.autonomous( autonomous );
Competiton.drivercontrol( usercontrol );

while(true) {
vex::task::sleep(100);
}
}

And, here is the code from robot-config.cpp

#include “vex.h”
using namespace vex;

// A global instance of brain used for printing to the V5 brain screen
brain Brain;

//VEXcode Devices
controller Controller1 = controller(primary);
motor LeftFrontDriveMotor (PORT1, ratio18_1,false);
motor LeftBackDriveMotor (PORT11, ratio18_1,false);
motor RightFrontDriveMotor (PORT10, ratio18_1,true);
motor RightBackDriveMotor (PORT20, ratio18_1,true);

/**

  • Used to initialize code/tasks/devices added using tools in VEXcode Text.
  • This should be called at the start of your int main function.
    */

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

Please, do not call changed() function inside the while(1) loop. First, it creates hundreds of tasks and then it will just be failing.

Instead, have your usercontrol() just call leftDrive() and sleep 10 msec inside the loop. Let us know if this fixes the problem.

4 Likes

@weilin We just tried executing leftFrontDriveMotor.spin directly from driver control. Same issue occurs where the wheel turns the wrong way… Good thought, though. Here is the code we tested.

void leftDrive() {
LeftFrontDriveMotor.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
LeftBackDriveMotor.spin(directionType::fwd, Controller1.Axis3.value(),velocityUnits::pct);
}

void usercontrol( void ) {
while(true) {
leftDrive();
vex::task::sleep(10);
}
}

@Shredder9181N We also agree that this port behavior is not typical of a burned out port, but is acting much more like a programming issue. Just not sure how to fix, or why the problem is exclusive to port 1.

Just to clarify, you are saying that if you change the motor from PORT1 in this line of code to PORT2 everything works as expected ? and the motor actually turns the other way with no other changes to the code, just moving from port1 to port2 ?

motor LeftFrontDriveMotor (PORT1, ratio18_1,true);

Have you tried deleting all programs on the brain and starting over ?

Which version of vexos is on the brain ? the latest we have released is 1.0.11.

4 Likes

@jpearman Yes, the change from Port1 to Port 2 in this line of text - along with physically moving the cable to Port 2 - makes the motor turn as expected. Just a note, we do have the reverse parameter set to false instead of true (as in the line of code in your post) because of the orientation of the motor on the robot.

Yes, we tried deleting all programs from the brain and reloading - this did not make a difference.

We just confirmed that the vexos on the brain in 1.0.11.

1 Like

yea, I had swapped the reverse flag when I was checking that PORT1 hadn’t developed some problem we did not know about. So I have some more simple questions.

motor LeftFrontDriveMotor (PORT1, ratio18_1, false);

and

  LeftFrontDriveMotor.spin( forward, 20, rpm );

should cause the motor in port1 to move in the direction of the red arrow on the motor housing, does it do that ?

changing the reverse flag, would cause the motor to spin the other way.

motor LeftFrontDriveMotor (PORT1, ratio18_1, true);

with the same spin command would cause it to rotate the other way, ie. opposite to the direction of the red arrow.

Are you saying that with both false and true the motor spins the same way ? which way is that wrt the red arrow ?

and if the only thing you change is the port number, then it all works ?

To be honest, if that is the case I have no idea why it would behave that way. The motor direction is controlled by a number we send to it, there’s nothing I can think of that would cause the issue you have, I can’t even think that a partially bad port would do that, especially if the motor controls correctly from the dashboard.

Have you tried the same test on another V5 brain ?

Perhaps send me the exact VEXcode project that is doing this.

5 Likes

Hey, so sorry for the delay in responding. I wanted to sit down with our programmer and double-check through all the code to confirm everything we were seeing. It turns out that there was another line of code in the config file that accidentally declared another motor on the same port. After fixing this, the problem went away. Kind of strange that a port being assigned twice to two separate motors would cause one of the motors to behave like this.

Thanks @jpearman and everyone else who helped us sort through this!

1 Like

No, that would be expected.
The global motor (or other device) constructers will be called one at a time when the programs starts in the order they are declared in the config file. If two motors are declared on the same port, whatever the second motor is doing with the reverse flag will be how the motor is actually set, this is because things like the reverse flag are set inside vexos and not stored inside the motor class.

3 Likes