@@ -32,6 +32,13 @@ struct _pbio_tacho_t {
3232
3333static pbio_tacho_t tachos [PBDRV_CONFIG_NUM_MOTOR_CONTROLLER ];
3434
35+ /**
36+ * Gets pointer to static tacho instance using port id.
37+ *
38+ * @param [in] port Port identifier.
39+ * @param [out] tacho Pointer to tacho object.
40+ * @return Error code.
41+ */
3542pbio_error_t pbio_tacho_get_tacho (pbio_port_id_t port , pbio_tacho_t * * tacho ) {
3643 // Validate port
3744 if (port < PBDRV_CONFIG_FIRST_MOTOR_PORT || port > PBDRV_CONFIG_LAST_MOTOR_PORT ) {
@@ -45,6 +52,13 @@ pbio_error_t pbio_tacho_get_tacho(pbio_port_id_t port, pbio_tacho_t **tacho) {
4552 return pbdrv_counter_get_dev (port - PBDRV_CONFIG_FIRST_MOTOR_PORT , & ((* tacho )-> counter ));
4653}
4754
55+ /**
56+ * Gets the tacho angle.
57+ *
58+ * @param [in] tacho The tacho instance.
59+ * @param [out] angle Angle in millidegrees.
60+ * @return Error code.
61+ */
4862pbio_error_t pbio_tacho_get_angle (pbio_tacho_t * tacho , pbio_angle_t * angle ) {
4963
5064 // First, get the raw angle from the driver.
@@ -64,6 +78,19 @@ pbio_error_t pbio_tacho_get_angle(pbio_tacho_t *tacho, pbio_angle_t *angle) {
6478 return PBIO_SUCCESS ;
6579}
6680
81+ /**
82+ * Resets the tacho angle to a given value.
83+ *
84+ * If @p reset_to_abs is true, the value will be reset to the absolute angle
85+ * marked on the shaft if supported. In this case, @p reset_angle serves as an
86+ * output so the caller knows which value it was reset to.
87+ *
88+ * @param [in] tacho The tacho instance.
89+ * @param [in] angle Angle that tacho should now report in millidegrees.
90+ * @param [in] reset_to_abs If true, ignores @p angle and instead resets to
91+ * absolute angle marked on shaft instead.
92+ * @return Error code.
93+ */
6794pbio_error_t pbio_tacho_reset_angle (pbio_tacho_t * tacho , pbio_angle_t * angle , bool reset_to_abs ) {
6895
6996 // If we reset to the absolute angle, we override the input angle. This
@@ -103,6 +130,16 @@ pbio_error_t pbio_tacho_reset_angle(pbio_tacho_t *tacho, pbio_angle_t *angle, bo
103130 return PBIO_SUCCESS ;
104131}
105132
133+ /**
134+ * Sets up the tacho instance to be used in an application.
135+ *
136+ * @param [in] tacho The tacho instance.
137+ * @param [in] direction The direction of positive rotation.
138+ * @param [in] reset_angle If true, reset the current angle to the current
139+ * absolute position if supported or 0. Otherwise it
140+ * maintains its current value.
141+ * @return Error code.
142+ */
106143pbio_error_t pbio_tacho_setup (pbio_tacho_t * tacho , pbio_direction_t direction , bool reset_angle ) {
107144
108145 pbio_angle_t zero = {0 };
0 commit comments