Controlling Motors

Motors

Get a motor and appropriate controller.

Wire to power and CAN and set CAN ID either through phoenix tuner (works over WIFI) for CTRE motor controllers or REV hardware client (connect with usb-c to any REV motor controller on the CAN bus) for rev motor controllers.

Controlling a Motor

Open Loop

If you need to control the speed a motor is going and it doesn't need to be very precise then you can just set a motor output percent or voltage. This is called open loop control and is called that because there is no information from real life getting fed back into the control input.

Closed Loop

If you need to control the position something is at or need accurate control over the speed then we will need some way to measure what we are trying to control so that we can adjust how much power we are providing to the motor. Most often this is a encoder which measures the rotation of a shaft but could be any sensor such as a gyro or vision system.

We then need some way to decide how much power to command to the motor to reach our goal, this is the job of a PID controller.

*pid controller tutorial link*


PID can be made to work well in many circumstances however it can be hard to tune and can be improved. To improve it we use our knowledge about the system to predict what input we will need before there is any error.

  • feedforward (SimpleMotorFeedforward, sysid)

  • trapezoidal motion profile

    • smart motion on motor controllers

  • voltage compensation

https://docs.wpilib.org/en/stable/docs/software/advanced-controls/index.html