int64_t setpoint instead of float?

General topics and discussions about the VESC and its development.
arvidb
Posts: 206
Joined: 26 Dec 2015, 14:38
Location: Sweden, Stockholm

int64_t setpoint instead of float?

Postby arvidb » 27 Aug 2016, 13:08

Would it be a good idea to use int64_t instead of float for the position setpoint (and internal actual position)?

The reason I ask is that float (or "Single-precision binary floating-point") can only represent about six significant digits (23 bits). So even before we reach 1 million degrees (or more exactly at 2098 revolutions) the precision of a float is less than one step on a 1000 pulses/rev quadrature encoder.

With int64_t on the other hand, and setting the unit as 1 µradian, the range is better than ±1,400 billion revolutions (enough, I think? :)).

The PID calculations could still be done as float, since the error represents a difference between the setpoint and the actual position (and if the pid-error is huge maybe it could be limited to a sane range without too many bad side effects?).

int64_t is supported by gcc on arm. I don't know about the performance cost though. One complication is that int64_t accesses would be non-atomic, so one would have to use mutexes whenever several threads wants to access a variable. But that's better than just declaring everything volatile anyway, so... :)

Any thoughts on this? Have I missed something?

Return to “General”

Who is online

Users browsing this forum: No registered users and 5 guests