I want to make a closed loop speed control VI to get a very accurate speed for the motors to run. I know how to calculate the speed using encoders but is there a different way to tell the victor what speed to set the motor to? I feel that the Set Motor Speed VI is not very accurate.
Presumably, you are using the Motor Set Speed VI, which in spite of its name, sets the percentage of time that the motor is given full current. In order to control the speed of the motor, you’ll want to use some form of control to close the loop – as the topic correctly states.
If you are having trouble getting the basic I/O, there is LV example called Motor with Encoder that you can compare to.
If the control is the difficult part, I’d add a PID VI to the loop and use the measured encoder speed, the target speed, and the PID coefficients to tune the controller.
The Set Motor Speed VI is a mis-nomer. It doesn’t set motor speed, it sets motor voltage (via PWM). Under certain idealized conditions motor speed will be proportional to motor voltage, but this is rarely the case with the motorized applications in FIRST. That’s why it is not accurate.
If you want closed-loop speed control, you can run the encoder signal to the cRIO and create your own PID control or use a library function. Or, use the Jaguars instead of the Victors. The Jags have built-in closed-loop speed control if you command them via CAN bus and feed the encoder signal directly to them. Which raises the question: has there been a clear ruling from GDC whether or not this is permissible?
Yes, it is legal. The rules are very clear that the Jaguars’ CAN functions are very legal this year.
Summarized, the rules are:
- If you drive a Jaguar with PWM, pretend it is a victor (no fancy inputs).
- If you drive a Jaguar with CAN, don’t plug in PWM, but have fun with everything else.
The ruling is directly in the manual, see <R68-H>:
<R68> All outputs from sensors, custom circuits and additional electronics shall connect to only
A. other custom circuits, or the following:
B. additional COTS electronics, or
C. input ports on the Digital Sidecar, or
D. input ports on the Analog Breakout, or
E. the RS-232 DB-9 serial port on the cRIO-FRC, or
F. the Ethernet bus connected to Port 2 of the cRIO-FRC, or
G. the CAN-bus if and only if all Jaguar speed controllers on the CAN-bus are wired in full compliance with Rule <R63> and Rule <R64>, or
H. the sensor inputs on the Jaguar speed controller.
What you want is a PID loop. Search the term here in Chief Delphi, particularly in the White Papers section.
What a PID loop does is look at the motor’s speed, compare it to what you have told it you want as the motor’s speed, and increases (or decreases) the motor speed so they match.
You wrote “Very Accurate” but what exactly do you mean? +/- 100 RPM? +/1 1 RPM? As you might guess, these are both pretty accurate, but one takes a lot more effort than the other. Also, if your load is fairly constant, it is a lot easier than if your load varies widely.
You can get tighter control of the motor by making your loop run faster. If you run the loop at 100 times per second, you can maintain better control than if you run it once per second, for example.
If you read the papers and still don’t understand, just ask. We love explaining PID.
I know what a PID is I have already written code to tell how far the robot should go in autonomous. (If you watch a video of us during Grand Valley you’ll see that we move back and fourth because we over shot our specified distance) Thanks for the help though. I understand victors now though.
FYI, the Jags run closed-loop at 1000 Hz.
Would that include the limit switches as well? Someone suggested in another thread that limit switch inputs to Jags were prohibited if Jags were being controlled via PWM.
L. If CAN-bus functionality is used, limit switch jumpers may be removed from a Jaguar speed controller and a custom limit switch circuit may be substituted (so that the cRIO-FRC may read the status of the limit switches).
A: Please see Rule <R60-L>. You may use the limit switch inputs to the Jaguar speed controllers IF you are controlling the Jaguar via a CAN-bus connection. You can not use external limit switch inputs to the Jaguars if you are controlling them via PWM inputs.
You may use the limit switch inputs to the Jaguar speed controllers IF you are controlling the Jaguar via a CAN-bus connection. You can not use external limit switch inputs to the Jaguars if you are controlling them via PWM inputs.
My question is with the wording of the Q&A response. Either the grammar is not correct, or the GDC was trying to be helpful and share a (possibly not correct) limitation of the Jag’s capabilities that does not seem to be documented in any of the Jag literature.
“You may use the limit switch inputs to the Jaguar speed controllers IF you are controlling the Jaguar via a CAN-bus connection.”
“You can not use external limit switch inputs to the Jaguars if you are controlling them via PWM inputs.”
I can find nothing in the Jag literature that says you can not use the limit switch inputs when commanding via PWM.
Did the GDC really mean “can not” or did they intend to communicate “shall not” or “are not permitted to” ?
Does anyone know if the limit switch inputs on the Jags work when the Jag is being commanded via PWM? And if so, has there been a clarification from GDC as to whether they intended to prohibit such use?
They mean “may”, not “can”.
The limit switches do work with PWM mode, it is simply not allowed.
May I ask, without any sense of disrespect whatsoever, how do you know this?
I kind of get the impression that your word on certain matters is authoritative (you seem to be quite knowledgeable about cRIO hardware for example), but being somewhat new around here, I do not know from whence that authority arises.
Sorry! No offense taken, I’ll try to tone it down a bit.
I designed the kit of parts electronics that are encased in blue plastic (PD, DSC, and the breakouts) as well as some of the kit sensor boards (2009 and 2010 Gyro and Accelerometer).
I also did a bit of the architectural legwork before the project really kicked off in earnest. This puts me at a disadvantage, because sometimes I know what it was supposed to do 3-4 years ago, and not what it actually does now. Also, I don’t touch software.
You can test the Jaguar limit inputs for yourself (I did) under PWM control.
Simply pull out the jumpers one at at time test Jaguar motion and replace.
It’s one of the fault conditions we have people check for when their Jags don’t work in one direction or another.
I have no official standing as does Eric however. I just tinker a lot and visit a bunch of teams who’s purpose in life often seems to be to break things in interesting and unique ways…
What a great idea. And so easy. Thanks.
If I had more convenient access to the hardware I’d probably start thinking along those lines more often.
My point of course is that testing or other direct experience (sometimes bad experiences) will be the source of most of the answers you find on this forum.
Authoritative answers in the traditional sense, such as Eric’s and Greg’s, are rare.