RT-Thread-packages / rt-robot

a platform in creating new exciting robots
Apache License 2.0
111 stars 62 forks source link

wheel: improved rpm calculation for wheels #28

Closed uLipe closed 4 years ago

uLipe commented 4 years ago

I improved the wheel speed to rpm calculations by replacing the division to a pre-computed expression, then a reciprocal multiply was added. Using this scheme we gain speed in two perspectives:

1 - the speed to rpm constant is calculated only once, that is it when the wheel object is allocated; 2 - typical microcontrollers (and processors) have a single / two cycle multiplication instruction and its divistion instruction is non-deterministic, so where allowed I replaced the division by a reciprocal multiplication, this will hints the compiler to remove the division and add a simple multiplication in place speeding up the result and adding determinism to that.

Please let me know your thoughts.

uLipe commented 4 years ago

I almost forgot to rebase with current master, sorry for that, solved on last commit :)

wuhanstudio commented 4 years ago

Thanks for your help. I'm sorry that I was attending HUAWEI 2019 Connect Conference (Advance Intelligence) on 9.19 and 9.20, thus not able to work on this until now.

Replacing the division with a reciprocal multiplication using a pre-computed value will indeed reduce computation at the cost of negligible extra memory allocation. But it seems some extra modifications are required to make it work as suggested in review.

uLipe commented 4 years ago

Fixed @wuhanstudio , thanks for the advice, now it should work as intended :)