Controlling V5 flywheel speed with VCS

With the Cortex there was a lot of programming to be done for flywheels. It was somewhat complex and close to beyond me unless I picked through it slowly. The kids I was working with were using some sort of @jpearman 's Take Back Half program and concepts.

With VCS is it as easy as setting the target RPM?
Only slightly more complicated (if you have a 2 wheel flywheel) would be to set the right side RPM, and have the left side target the right’s actual RPM.

Are there any tips for ramping up/down single flywheels with VCS?

In my experience, no. The internal PID overshoots in both directions (speeding up and slowing down).

Custom PID or other algorithms (TBH, etc.) will probably be necessary.

Pseudocode:


function flywheel(targetSpeed)
  //Percent; maximum speed difference per ramping step; tweak as desired
  persistent constant speedDelta = 10

  //Milliseconds; minimum delay between ramping steps; tweak as desired
  persistent constant period = 1000

  //Milliseconds; initial value should be less than -period
  persistent var lastExecutionTime = -2000

  if currentSystemTime - lastExecutionTime ≥ period
    if abs(targetSpeed - currentSpeed) > speedDelta
                        //abs() = absolute value
      setSpeed(currentSpeed + ((targetSpeed - currentSpeed) /
                        abs(targetSpeed - currentSpeed)) * speedDelta)
                        //setSpeed(currentSpeed + (±1) * speedDelta)
    otherwise
      setSpeed(targetSpeed)
    end if
    set lastExecutionTime = currentSystemTime
  end if
end function flywheel

My


persistent

keyword corresponds to the


static

keyword in C/C++

This function is designed to be completely safe to call in your main execution block (assuming


setSpeed()

is safe). You can set your main execution loop’s frequency to any reasonable value and my implementation will work.

Does VCS even have the ability to override the built in motor PID currently? I remember manual PWM was mentioned as a method for controlling the motor, but I don’t see any reference for if/how you can impliment it.

As far as I can tell, no, which is extremely limiting for teams using VCS. I tried looking through the entire VCS API so I could use voltage control on my drive (which is far easier to control), but ended up switching to PROS.

Well I was digging through the API files and found an undocumented function that would presumably set PWM for a motor:


void                  vexDeviceMotorPwmSet( V5_DeviceT device, int32_t value );

Also found some functions that might help modify motor PID


void                  vexDeviceMotorPositionPidSet( V5_DeviceT device, V5_DeviceMotorPid *pid );
void                  vexDeviceMotorVelocityPidSet( V5_DeviceT device, V5_DeviceMotorPid *pid );

Will try to experiment…

The PWM and Motor PID functions are exposed in the PROS API. You can find more information about how these functions work in their PROS documentation entries:

  • is analogous to

vexDeviceMotorPwmSet() 

  • function describes the various parameters that can be set to the Motor PIDs, as well as how they need to be formatted.

These functions are all part of the standard PROS API, and are paired with some additional functions that are designed to make the Motor PIDs easier to modify.