Only lowest cortex motor port working - Unofficial answer

This was originally posted in the official questions section.

The code you posted will not work correctly, the main task terminates with unpredictable results. Try this slightly modified version, it should run both motors.

#pragma config(UART_Usage, UART2, uartNotUsed, baudRate4800, IOPins, None, None)
#pragma config(Motor, port2, test2, tmotorVex393, openLoop)
#pragma config(Motor, port3, test3, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
    motor[test3] = 60;
    motor[test2] = 60;

    while(1)
        wait1Msec(10);
}

The while loop at the end stops the task terminating.

If you want joystick control try this.

#pragma config(UART_Usage, UART2, uartNotUsed, baudRate4800, IOPins, None, None)
#pragma config(Motor, port2, test2, tmotorVex393, openLoop)
#pragma config(Motor, port3, test3, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
    while(1)
        {
        motor[test3] = vexRT Ch3 ];
        motor[test2] = vexRT Ch2 ];

        wait1Msec(10);
        }
}

happy coding.

1 Like

The compiler sees your code as

task main()
{
while(true) motor[test3] = 60;
motor[test2] = 60;

}

So it’s in a loop doing motor[test3] = 60; over and over and over… So it never gets to motor2, which is what your test results showed.

the addition of the braces {} around the motor statements makes them a block for the while() statement.


task main()
{
while(true)  {  
     motor[test3] = 60;
     motor[test2] = 60;
}
}

Sometimes it pays to read the code aloud, so the first example would be

while true motor on port 3 assigned 60 next (the semi)

second would be

while true do block of motor on port 3 assigned 60 next motor on port 2 and thats the end of the while true block.

I try to put comments in to help match up the braces


task main()
{
while(true)  {  // begin master loop
     motor[test3] = 60;
     motor[test2] = 60;
} // end master loop 
}
1 Like