Skip to content

Commit 635ae0d

Browse files
committed
pbio/tacho: Document module.
1 parent de95610 commit 635ae0d

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

lib/pbio/include/pbio/tacho.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
/**
55
* @addtogroup Tacho pbio/tacho: Rotation sensor interface
66
*
7-
* Extends a rotation sensor with a configurable positive direction and zero point.
7+
* Extends a rotation sensor with a configurable positive direction and zero
8+
* point without resetting hardware.
89
* @{
910
*/
1011

lib/pbio/src/servo.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ pbio_error_t pbio_servo_reset_angle(pbio_servo_t *srv, int32_t reset_angle, bool
275275
pbio_angle_t new_angle;
276276
pbio_control_settings_app_to_ctl_long(&srv->control.settings, reset_angle, &new_angle);
277277

278-
// Reset the tacho to the new angle.
278+
// Reset the tacho to the new angle. If reset_to_abs is true, the
279+
// new_angle will be an output, representing the angle it was set to.
280+
// This lets us use it again to reset the observer below.
279281
err = pbio_tacho_reset_angle(srv->tacho, &new_angle, reset_to_abs);
280282
if (err != PBIO_SUCCESS) {
281283
return err;

lib/pbio/src/tacho.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ struct _pbio_tacho_t {
3232

3333
static 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+
*/
3542
pbio_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+
*/
4862
pbio_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+
*/
6794
pbio_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+
*/
106143
pbio_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

Comments
 (0)