What is the usage for the breaking functions (setActiveBreaking, setPassiveBreaking)?
Active braking gives you a better control over the motor and is preferable for small DC motors in most cases. The passive braking is safer for the motor, and if your motor is not strongly overloaded or is not overheating, you probably don’t need passive braking. This is a hardware-related thing and the topic for the article, not for a short answer
How can I limit the voltage for a 6V motor (I assume the function is setPowerLimit, but how to set the limit parameter)? Is the setPower value relative to the power input?
The setPower sets the average output voltage in relation to the input voltage, so with the input voltage for CORE2 Vs = 9V and power value = 666, the output voltage for motor will be 9V*666/1000 =~ 6V.
The setPowerLimit only sets the limit, so after this line:
you will not be able to set the power for hMot1 greater that 500. When you set 400, the resulting value will be still 400. When you set 800, the resulting value will be 500 (maximum) - also relative to the input voltage Vs.
What is the slew rate for and how works it?
In many applications, when you control motor, you don’t want it to reach final speed as fast as possible. Imagine that you make an internet controlled car. If you execute setPower(1000) on it’s motors, the acceleration is so large, that the front of the car lifts up. If you specify slew rate, the final speed is the same (1000 = 100% PWM), but the acceleration is lower.
The “time” value used as an argument to setSlewRate(time) method is not straightforward.
For time=0 and time=1, the setSlewRate() has no effect on the motor power.
For 0 < time < 1, the smaller the value, the longer is the acceleration.
For example, for time=0.1 you will get about half of the maximum power after about 66ms.
When time=0.01, you will get the half of the maximum power after about 660ms.
The power is updated every 10ms and the equation is:
power(t) = slewTarget*(1-(1-time)^0.1t),
t - time in [ms]
time - an argument for setSlewRate() method
slewTarget - target power value (-1000 … 1000)
What is the queue for the motor (mentioned in waitDone) and how is it used/filled?
Take a look at waitDone method:(https://github.com/husarion/hFramework/blob/master/ports/stm32/src/hMotorPimpl.cpp).
It contains not a queue but a mutex. If you execute for example rotRel, method mutex is blocked until rotation is done, or timeout occured. Motor regulator works in the separate task. Mutex is used to communicate whether motor task has finished its work.
We are working to improve the API, but there is a lot of work to do. Updates will be appear regularly.