It may be a couple more weeks before we release an updated SDK for VCS with open loop motor control. So in the meantime I’m going to post some code that the more advanced teams can use who really want to turn off the PID control in the V5 motor and control it more directly. Use at your own risk, I haven’t tested using lots of open loop control along with methods such as rotateTo which will turn PID back on.
To keep some forwards/backwards compatibility the best way to approach this is to use a sub class of vex::motor and add one new method that takes the same parameters as we will have in the next SDK version.
// sub class motor to add new method
namespace vex {
class motor_special : public motor {
private:
uint32_t _local_index;
public:
motor_special( int32_t index ) : motor( index ), _local_index(index) {};
~motor_special() {};
// Allow overloading of base class methods
using motor::spin;
// This is similar, not quite the same, as new a method in the next (Nov ?) SDK release
// voltage can be +/-12.0 volta or +/-12000 mV
void spin( directionType dir, double voltage, voltageUnits units ) {
// convert volts to mV is necessary
int32_t voltage_mv = (units == voltageUnits::volt ? voltage * 1000.0 : voltage );
// flip based on direction flag
voltage_mv = (dir == directionType::fwd ? voltage_mv : -(voltage_mv) );
if( voltage_mv == 0 ) {
stop();
} else {
// send mV value to control motor open loop
vexMotorVoltageSet( _local_index, voltage_mv );
}
}
};
}
you would then create an instance of a motor using the new class, for example
motor_special Motor1( vex::PORT1 );
The new method can be called like this.
Motor1.spin( directionType::fwd, 2.0, voltageUnits::volt );
or this
Motor1.spin( directionType::fwd, 2000, voltageUnits::mV );
they are equivalent
to send values directly from the controller, you would need to rescale controller axis values like this.
while(1) {
double v = (double)Controller1.Axis1.value() * 12.0 / 127;
Motor1.spin( directionType::fwd, v, voltageUnits::volt );
this_thread::sleep_for(20);
}
I will attach a VCS demo
To use with VEX C++ you would need to create either additional instances of your motors or abandon using the config screen at all. This cannot be used with blocks programming.
motor_open_loop_control_pro.vex (5.5 KB)