Skip to content

Commit 044f29e

Browse files
committed
pbio/trajectory: Store user given speed.
This value can be used during control to test if the original speed target was low. This can be used to reduce the control gains to increase stability as a tradeoff against stiffness. We use the user given speed instead of the actual top speed, so that this won't affect commands that have low just only because the maneuver is short.
1 parent 956fd10 commit 044f29e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/pbio/include/pbio/trajectory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ typedef struct _pbio_trajectory_t {
6666
int32_t th1; /**< Encoder count after the acceleration in-phase */
6767
int32_t th2; /**< Encoder count at start of acceleration out-phase */
6868
int32_t th3; /**< Encoder count at end of maneuver */
69+
int32_t wu; /**< Encoder rate target originally given by user */
6970
int32_t w0; /**< Encoder rate at start of maneuver */
7071
int32_t w1; /**< Encoder rate target when not accelerating */
7172
int32_t w3; /**< Encoder rate target after the maneuver ends */
@@ -83,6 +84,7 @@ void pbio_trajectory_stretch(pbio_trajectory_t *trj, pbio_trajectory_t *leader);
8384
// Reference getter functions:
8485

8586
uint32_t pbio_trajectory_get_duration(pbio_trajectory_t *trj);
87+
int32_t pbio_trajectory_get_abs_command_speed(pbio_trajectory_t *trj);
8688
void pbio_trajectory_get_endpoint(pbio_trajectory_t *trj, pbio_trajectory_reference_t *end);
8789
void pbio_trajectory_get_last_vertex(pbio_trajectory_t *trj, uint32_t time_ref, pbio_trajectory_reference_t *ref);
8890
void pbio_trajectory_get_reference(pbio_trajectory_t *trj, uint32_t time_ref, pbio_trajectory_reference_t *ref);

lib/pbio/src/trajectory.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static void reverse_trajectory(pbio_trajectory_t *trj) {
9191
trj->th3 = -trj->th3;
9292

9393
// Negate speeds and accelerations
94+
trj->wu *= -1;
9495
trj->w0 *= -1;
9596
trj->w1 *= -1;
9697
trj->w3 *= -1;
@@ -119,8 +120,7 @@ void pbio_trajectory_make_constant(pbio_trajectory_t *trj, const pbio_trajectory
119120
pbio_trajectory_set_start(&trj->start, c);
120121

121122
// Set speeds, scaled to ddeg/s.
122-
trj->w0 = to_trajectory_speed(c->speed_target);
123-
trj->w1 = to_trajectory_speed(c->speed_target);
123+
trj->w0 = trj->w1 = trj->wu = to_trajectory_speed(c->speed_target);
124124
trj->w3 = c->continue_running ? to_trajectory_speed(c->speed_target): 0;
125125
}
126126

@@ -256,7 +256,7 @@ static pbio_error_t pbio_trajectory_new_forward_time_command(pbio_trajectory_t *
256256
// Speed continues at target speed or goes to zero. And scale to ddeg/s.
257257
trj->w3 = c->continue_running ? to_trajectory_speed(c->speed_target) : 0;
258258
trj->w0 = to_trajectory_speed(c->speed_start);
259-
int32_t wt = to_trajectory_speed(c->speed_target);
259+
int32_t wt = trj->wu = to_trajectory_speed(c->speed_target);
260260
int32_t accel = to_trajectory_accel(c->acceleration);
261261
int32_t decel = to_trajectory_accel(c->deceleration);
262262

@@ -365,7 +365,7 @@ static pbio_error_t pbio_trajectory_new_forward_angle_command(pbio_trajectory_t
365365
// Speed continues at target speed or goes to zero. And scale to ddeg/s.
366366
trj->w3 = c->continue_running ? to_trajectory_speed(c->speed_target) : 0;
367367
trj->w0 = to_trajectory_speed(c->speed_start);
368-
int32_t wt = to_trajectory_speed(c->speed_target);
368+
int32_t wt = trj->wu = to_trajectory_speed(c->speed_target);
369369
int32_t accel = to_trajectory_accel(c->acceleration);
370370
int32_t decel = to_trajectory_accel(c->deceleration);
371371

@@ -669,6 +669,20 @@ void pbio_trajectory_get_endpoint(pbio_trajectory_t *trj, pbio_trajectory_refere
669669
pbio_trajectory_offset_start(end, &trj->start, trj->t3, trj->th3, trj->w3, 0);
670670
}
671671

672+
/**
673+
* Gets the originally commanded speed for the current trajectory, even if
674+
* this top speed is not reached.
675+
*
676+
* This is an indicator of the expected speed, which may be used to to alter
677+
* control behavior for motion with sustained low speed values.
678+
*
679+
* @param [in] trj The trajectory instance.
680+
* @return The user given speed in control units.
681+
*/
682+
int32_t pbio_trajectory_get_abs_command_speed(pbio_trajectory_t *trj) {
683+
return to_control_speed(pbio_int_math_abs(trj->wu));
684+
}
685+
672686
// Get trajectory endpoint.
673687
uint32_t pbio_trajectory_get_duration(pbio_trajectory_t *trj) {
674688
assert_time(trj->t3);

0 commit comments

Comments
 (0)