Hi there! I’m trying to setup a pid loop using pwm controllers and an encoder. We’re to the point of where we can read the encoder values and control the motor, but it looks like all the nifty built in functions are build for the smart motors, not pwm based controllers. Am I right in assuming that? Or are there build in pid functions in the vex libraries and I’m just missing them? If not, are there any good writeups or examples anywhere of implementing a pid loop on the vex controllers? Thanks!
are you referring to legacy 393 motors connected to the 3wire ports ? (or I guess any motor using PWM with a suitable motor controller connected to a 3wire port). If so, no there is very little support for those.
Yea, we’re using the rev robotics spark controllers, and I believe we’re actually controlling them with the pwm_out class instead of the motor 393 class.
(This forum is for vex, you are using frc electronics, so chief delphi will actually be able to help you)
Edit: you can only control certain motor controllers using a vex v5 brain, but they are brushed and old
We’re using the vexcode v5 brain for the main controller, but we’re plugging in a pwm speed controller to control the motor. So it is vex, from the coding standpoint.
There is a choice of three classes for controlling pwm motors.
The pwm class is very simple, one class member function that lets you set the raw pwm value.
The motor29 (for using MC29 motor controller) class used with motors receiving power from the 3wire port, of which there is little, adds a few simple commands like spin and stop. That class also tries to disallow rapid changes of speed to limit transient current.
The motor_victor class is similar to motor29 but removes the current limit code as it assumes the controller and motor will use an external power source.
The only reason we support motors on the 3wire ports was really for classroom use, they are not legal for use in the VEX Robotics Competition.
Anyway, you are pretty much on your own in terms of implementing and PID control, you will find some code from a few years ago for the older cortex controller, that can probably be ported over to VEXcode.
You are just gonna have to code your own pid then, this is the resource I usually send everyone:
Ah, thanks. This is for a non-vex competition that uses the vex hardware, so we can use whatever speed controllers we like. I guess we’ll look at digging around the for the cortex stuff or just writing our own pid control loops.
… there’s a way to limit current to the adi ports? doesn’t that mean there’s also a way to measure current to the adi?
when you start a motor there’s a large transient current. If you gradually ramp up speed on a motor the transient current is much reduced (ie. what we generally call slew rate control). That’s all we are doing on the 3wire ports, we needed two 393 motors to run without tripping the 2A limit on the voltage regulator. There’s no way to measure actual current for the 3wire ports.