Incorporate DC Motor Characteristics as Optional Parameters
CedarGroveStudios opened this issue · 5 comments
- Abstracting duty cycle to a -1.0 to +1.0 motor speed parameter could be improved to match actual motor speed by including the spin threshold voltage of the target DC motor. Since a DC motor's spin threshold voltage can be 10% to 20% of the DC motor's voltage range (1 to 2 volts for a 6-volt motor), a noticeable dead zone exists as the speed parameter value approaches zero. For example, the motor may stop spinning when the PWM duty cycle is less than 20%. The spin threshold is motor dependent and can be derived from the motor datasheet or through experimentation. Incorporating spin threshold would require that the motor controller's supply voltage be known by the driver.
- Limiting maximum duty cycle to match the DC motor's maximum voltage would allow the use of motors with maximum ratings lower than the motor controller's power source, while maintaining a full -1.0 to +1.0 motor speed parameter range. When powering a 3-volt motor from a 5-volt power source, for example, the speed parameter value for maximum speed would be +1.0 for the forward direction. This would also prevent overdriving the motor and/or motor controller board. The maximum voltage is motor dependent and can be derived from the motor datasheet or through experimentation. Incorporating a maximum voltage limit would require that the motor controller's supply voltage be known by the driver.
Both good ideas! This sounds very similar to the tuning that can be done for servo timing. Perhaps we could add min_duty_cycle
and max_duty_cycle
kwargs to the constructor. This would be similar to min_pulse
and max_pulse
for servo.
That would certainly help provide trim values for a larger variety of DC motors and would be an economic solution.
I'm moving towards the next level of abstraction where the motor speed parameter value is equivalent to motor speed rather than the motor controller's duty_cycle. For example, a 6-volt motor with a 2 volt spin threshold operating from a 9-volt battery power source has a stop_duty_cycle
of 22% and max_duty_cycle
of 67%. When the battery voltage decays to 8 volts, stop_duty_cycle
and max_duty_cycle
values change to 25% and 75% to continue to observe the spin threshold and optimum (maximum) voltage of the motor (2 volts and 6 volts). Ultimately, a motor speed parameter value of 0 would be just below the spin threshold of the motor; a value of +1.0 would be the full rated speed of the motor, regardless of the changes to the motor controller's power supply voltage (providing that it is monitored as in the case of a battery supply). The motor speed parameter would then relate more closely to the motor's speed rather than the motor controller's duty_cycle value.
An added benefit is seen when swapping out the motor or the power source. Only the static attributes for the motor or power source need to change.
Ah! That could be done inside the class or on the outside by a battery monitoring routine.
Agree. Including duty_cycle trim value kwargs would be a useful feature.
I'll eventually have some examples of the battery and motor attribute -centric approach with an accel/decel (simulated inertia) module. Probably will post those as part of a model train controller learning guide.
Modified the simulated inertia algorithm from the DC motor version used in the string car to work with x-y servos. Sent a copy to John Park to try as a movement smoothing approach for his recent workshop pan/tilt project.
Code snippet is here galvanometer