# PWM and accuracy

I’ll jump right into it:

Say that in the workshop we’re testing for autonomous mode, specifically for the drive system. We obviously want the wheels to be able to reach the same speed during the match as the one that worked in the workshop.

If the motors are connected to CAN speed controllers, I could just programatically read the current on them and then tell the program to send the same vlue of ControlMode.Current. But say that this weren’t an option, for any reason (and I should probably state that for now it’s hypothetical).

So say it’s a speed controller connected via PWM, which only allows me to send a percentage. Say that in the workshop, we found that a percentage p0 works. To my understanding, this would be the same result if the battery voltage would be the same during the match as it were during testing (is that right?). But what if it weren’t? Say, let’s denote the voltage during testing as V0 and the one on the field as Vf.

I think there should be a formula depending on p0, V0, Vf to tell you which percentage to send to the motor, but what would that be and why? I do know some physics (specifically: DC circuits, power, voltage, current), and I do kinda know how PWM works (what with all the terms like duty cycle and pulse width, that I do understand), but I’d love to hear if someone knows a better way. I’m assuming that even if the relation isn’t linear, linear approximations are often good enough (that is, I’d send a value equal to p0Vf/V0*). But I do want to know if you can help me find something more reliable.

BTW, if anyone’s interested, this is hypothetical for now, but being that close to the end of the season, I want the students in my team’s programming crew to be able to write a code that’s ready for any scenario (in the case: a drive system on PWM controllers instead of CAN).

[RIGHT]Best regards,

Yuval D

Mentor (Teams #4661, #2212)[/RIGHT]

FYI: The PDP also measures current.

*You can read the battery voltage Vbat in your code.

Multiply your PWM command by 12/Vbat before sending it to your motor controller.

So when your battery voltage drops, you automagically send a higher command to your motor controller, to compensate.

If you use the scaling described above in your workshop, you don’t have to make any changes for the field.

Motor power is roughly a square of the voltage - remember Ohm’s law, and a I”m aware a motor is not the same as a resistor. Current is proportional to voltage, and so wattage (electrical power) is a function of the square of the voltage. I’d try using the product of the measured voltage and the measured current to scale your PWM value.

I got a reality check early in my mentoring when I learned that a robot doesn’t go straight when identical power is applied to both L and R drivetrains. And a robot this isn’t consistent over multiple drives.

There is a lot of stuff about motor characteristics on the Web, along with design tools, and this is NOT the time in the build season to spend time on those. You need the finish your ‘bot.

In Israel you get to watch the Kickoff broadcast at dinner time, don’t you?

Well Israelis tend to eat dinner a lot later than Americans (closer to 8-9p), but yes the kickoff here is usually sometime between 5-6p. Bag and tag is 7am the next day, so we usually end up pulling an all nighter.

Back to the original question, you really want to use encoders on your drivetrain to measure how far the wheels are actually spinning. From there, you can use a closed loop controller to make the robot go exactly how far you want in autonomous. Without encoders your method will help you get closer to reality, but at the end of the day if you want cm accuracy you need closed loop control.

If you want help with this, I can ask someone from my programming team to call your programmers and try to help them (since it’s probably easier for them to discuss in Hebrew).