Make feed override control the WASM trajectory
This commit is contained in:
@@ -12,6 +12,7 @@ typedef struct motion_meta {
|
||||
uint32_t lookahead;
|
||||
double acceleration_limit;
|
||||
double jerk_limit;
|
||||
double feed_override;
|
||||
double current_velocity;
|
||||
double current_acceleration;
|
||||
uint32_t paused;
|
||||
@@ -34,6 +35,7 @@ static motion_meta *meta_for(const sim_motion_queue *queue, int create) {
|
||||
free_slot->lookahead = 1;
|
||||
free_slot->acceleration_limit = 1e9;
|
||||
free_slot->jerk_limit = 1e12;
|
||||
free_slot->feed_override = 1.0;
|
||||
free_slot->paused = 0;
|
||||
return free_slot;
|
||||
}
|
||||
@@ -106,6 +108,7 @@ int sim_motion_reset(sim_motion_queue *queue) {
|
||||
meta->lookahead = 1;
|
||||
meta->acceleration_limit = 1e9;
|
||||
meta->jerk_limit = 1e12;
|
||||
meta->feed_override = 1.0;
|
||||
meta->current_velocity = 0.0;
|
||||
meta->current_acceleration = 0.0;
|
||||
meta->paused = 0;
|
||||
@@ -147,6 +150,13 @@ int sim_motion_set_dynamics(sim_motion_queue *queue, double acceleration_limit,
|
||||
return SIM_MOTION_OK;
|
||||
}
|
||||
|
||||
int sim_motion_set_feed_override(sim_motion_queue *queue, double feed_override) {
|
||||
motion_meta *meta = meta_for(queue, 1);
|
||||
if (meta == NULL || !isfinite(feed_override) || feed_override < 0.0 || feed_override > 2.0) return SIM_MOTION_ERR_RANGE;
|
||||
meta->feed_override = feed_override;
|
||||
return SIM_MOTION_OK;
|
||||
}
|
||||
|
||||
int sim_motion_set_paused(sim_motion_queue *queue, uint32_t paused) {
|
||||
motion_meta *meta = meta_for(queue, 1);
|
||||
if (meta == NULL || paused > 1u) return SIM_MOTION_ERR_ARGUMENT;
|
||||
@@ -174,11 +184,12 @@ static double planned_velocity(const sim_motion_queue *queue, uint32_t offset) {
|
||||
uint32_t index;
|
||||
if (queue == NULL || offset >= queue->count) return 0.0;
|
||||
index = (queue->head + offset) % SIM_MOTION_QUEUE_CAPACITY;
|
||||
velocity = queue->commands[index].segment.velocity;
|
||||
velocity = queue->commands[index].segment.velocity * (meta == NULL || (queue->commands[index].flags & SIM_MOTION_COMMAND_FLAG_RAPID) != 0u ? 1.0 : meta->feed_override);
|
||||
if (meta == NULL || meta->profile == SIM_MOTION_PROFILE_EXACT_STOP) return velocity;
|
||||
for (index = 1; index <= meta->lookahead && offset + index < queue->count; ++index) {
|
||||
uint32_t next = (queue->head + offset + index) % SIM_MOTION_QUEUE_CAPACITY;
|
||||
if (queue->commands[next].segment.velocity < velocity) velocity = queue->commands[next].segment.velocity;
|
||||
const double next_velocity = queue->commands[next].segment.velocity * ((queue->commands[next].flags & SIM_MOTION_COMMAND_FLAG_RAPID) != 0u ? 1.0 : meta->feed_override);
|
||||
if (next_velocity < velocity) velocity = next_velocity;
|
||||
}
|
||||
return velocity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user