Skip to content

Commit

Permalink
make the move message smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
ahiuchingau committed Nov 8, 2024
1 parent 34b7181 commit f83e7af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
4 changes: 2 additions & 2 deletions stm32-modules/include/common/core/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CircularBuffer {
return false;
}

_buffer[_tail] = item;
_buffer.at(_tail) = item;
_tail = (_tail + 1) % buffer_size;

if (full()) {
Expand All @@ -34,7 +34,7 @@ class CircularBuffer {
}

auto dequeue() -> T {
T item = _buffer[_head];
T item = _buffer.at(_head);
_head = (_head + 1) % buffer_size;
_count--;

Expand Down
27 changes: 8 additions & 19 deletions stm32-modules/include/flex-stacker/firmware/motor_interrupt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ static constexpr int TIMER_FREQ = 100000;

struct Move {
MotorID motor_id;
motor_util::MotorState* motor_state;
uint32_t move_id;
bool direction;
float speed;
float acceleration;
float speed_discont;
uint64_t steps;
float distance;
bool limit_switch;
bool has_next_move;
};
Expand Down Expand Up @@ -74,27 +72,18 @@ class MotorInterruptController {
_response_id = move_id;
}
auto start_move(Move move) -> void {
motor_util::MotorState* state = move.motor_state;
_stop = false;
set_direction(move.direction);
_profile = motor_util::MovementProfile(
TIMER_FREQ, move.speed_discont, move.speed, move.acceleration,
TIMER_FREQ, state->get_speed_discont(),
move.limit_switch ? state->get_speed_discont() : state->get_speed(),
state->get_accel(),
move.limit_switch ? motor_util::MovementType::OpenLoop
: motor_util::MovementType::FixedDistance,
move.steps);
_policy->enable_motor(move.motor_id);
_response_id = move.move_id;
}

auto start_movement(uint32_t move_id, bool direction,
uint32_t steps_per_sec_discont, uint32_t steps_per_sec,
uint32_t step_per_sec_sq) -> void {
_stop = false;
set_direction(direction);
_profile = motor_util::MovementProfile(
TIMER_FREQ, steps_per_sec_discont, steps_per_sec, step_per_sec_sq,
motor_util::MovementType::OpenLoop, 0);
state->get_distance(move.distance));
_policy->enable_motor(_id);
_response_id = move_id;
_response_id = move.move_id;
}
auto stop_movement(uint32_t move_id, bool disable_motor) -> void {
_stop = true;
Expand Down
18 changes: 5 additions & 13 deletions stm32-modules/include/flex-stacker/flex-stacker/motor_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,32 +167,24 @@ class MotorTask {
return Error::NO_ERROR;
}


auto make_move(uint32_t id, MotorID motor_id, bool direction,
float distance, bool has_next_move = false) -> Move {
MotorState& state = motor_state(motor_id);
return Move{.motor_id = motor_id,
.motor_state = &motor_state(motor_id),
.move_id = id,
.direction = direction,
.speed = state.get_speed(),
.acceleration = state.get_accel(),
.speed_discont = state.get_speed_discont(),
.steps = state.get_distance(distance),
.distance = distance,
.limit_switch = false,
.has_next_move = has_next_move};
}

auto make_home_move(uint32_t id, MotorID motor_id, bool direction,
bool has_next_move = false) -> Move {
MotorState& state = motor_state(motor_id);
return Move{.motor_id = motor_id,
.motor_state = &motor_state(motor_id),
.move_id = id,
.direction = direction,
// slow speed to reach limit switch
.speed = state.get_speed_discont(),
.acceleration = state.get_accel(),
.speed_discont = state.get_speed_discont(),
.steps = 0,
.distance = 0,
.limit_switch = true,
.has_next_move = has_next_move};
}
Expand Down Expand Up @@ -278,7 +270,6 @@ class MotorTask {
}
Controller& controller = controller_from_id(m.motor_id);
MotorState& state = motor_state(m.motor_id);
auto direction = m.mm > 0;
if (m.mm_per_second.has_value()) {
state.speed_mm_per_sec = m.mm_per_second.value();
}
Expand All @@ -288,6 +279,7 @@ class MotorTask {
if (m.mm_per_second_discont.has_value()) {
state.speed_mm_per_sec_discont = m.mm_per_second_discont.value();
}
auto direction = m.mm > 0;
auto move =
make_move(m.id, m.motor_id, direction, std::abs(m.mm), false);
controller.start_move(move);
Expand Down

0 comments on commit f83e7af

Please sign in to comment.