@@ -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.
673687uint32_t pbio_trajectory_get_duration (pbio_trajectory_t * trj ) {
674688 assert_time (trj -> t3 );
0 commit comments