libhal-google / libhal

A collection of interfaces and abstractions for embedded peripherals and devices using modern C++
Apache License 2.0
86 stars 17 forks source link

Add `hal::orientation` interface #631

Open kammce opened 1 year ago

kammce commented 1 year ago

An interface representing the orientation of an entity. Such an entity can have 1D 2D or 3D orientation.

An example of a 1D orientation would be a rotary potentiometer. It has a single degree of rotational freedom and that's only has one degree of orientation.

An accelerometer to represent 2D orientation but so could a joystick represent 2D orientation. The reason accelerometers do not have more degrees of freedom is due to the fact that they cannot get y'all without some other reference that isn't gravity like a compass.

3D orientation can come from an IMU that provides yaw pitch and roll information.

There should also be consideration of whether or not there should be separate interfaces for each type of orientation 1D, 2D or 3D. The benefits of having separate types for each one are:

  1. APIs using specific interfaces will make it more clear and obvious to the developers what their expectations are. Taking a 3D orientation when you only want one dimension of orientation information can make the API a bit confusing.
  2. The cost of having to use a 3D orientation for all orientations is that you pay the cost of returning a larger data structure when you will never use these values.

Whether or not this particular interface should use were there angles or quaternions is up for debate. My personal preference would be or their angles as it's more intuitive for human beings to understand.