How to use V5 motor encoder using Robot Mesh Python

A couple of question about motor encoder program in Python:

How do I read the motor values (like speed) while driving/practice match? For instance, I wish to know the top speed of each of my motor when are is 2 of them powering 1 wheel.

How do I use encoder values as arguments in ‘if’ statements? For example, stop motor if it reaches 150RPM.

Thanks in advance

Are you programming for IQ, V5, or Cortex?

edit: Just actually read the thread title. Standby for better advice.

The basic method for reading an encoder value is rotation:

def vex.Motor.rotation ( self ,
rotationUnits = RotationUnits.DEG
)

Gets the current rotation of the motor’s encoder.

Parameters

rotationUnits Defines what the unity type of the value of rotation that is returned.

Returns

Returns a double that represents the current rotation of the motor in the units defined in the parameter.

For reading velocity, there is velocity:

def vex.Motor.velocity ( self ,
velocityUnits = VelocityUnits.PCT
)

Gets the current velocity of the motor.

Parameters

velocityUnits Defines the unit type of the velocity value returned.

Returns

Returns a double that represents the current velocity of the motor in the units defined in the parameter.

As for max speed, the usual way to do minima and maxima in programming is to keep track of the last minimum/maximum your code has seen, and compare the current value against it, updating the stored value as needed.

For using them inif statements, you just plop them in there like any other rvalue:

if motor1.velocity() > 50:
    motor1.stop()
1 Like

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