Skip to content

Commit e8ff8ae

Browse files
committed
Merge branch 'edge' into flex-stacker-tof-sensors-bringup
2 parents e383542 + ac33c93 commit e8ff8ae

17 files changed

+435
-93
lines changed

.github/workflows/flex-stacker-create-release.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: 'Prep for install'
4242
run: cmake --install ./build-stm32-cross --component flex-stacker
4343
- name: 'Save firmware artifacts'
44-
uses: actions/upload-artifact@v3
44+
uses: actions/upload-artifact@v4
4545
with:
4646
name: flex-stacker-build
4747
path: dist/flex-stacker/*.zip

.github/workflows/heater-shaker-create-release.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: 'Prep for install'
4242
run: cmake --install ./build-stm32-cross --component heater-shaker
4343
- name: 'Save firmware artifacts'
44-
uses: actions/upload-artifact@v3
44+
uses: actions/upload-artifact@v4
4545
with:
4646
name: heater-shaker-build
4747
path: dist/heater-shaker/*.zip

.github/workflows/thermocycler-gen2-create-release.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: 'Prep for install'
4242
run: cmake --install ./build-stm32-cross --component thermocycler-gen2
4343
- name: 'Save firmware artifacts'
44-
uses: actions/upload-artifact@v3
44+
uses: actions/upload-artifact@v4
4545
with:
4646
name: thermocycler-gen2-build
4747
path: dist/thermocycler-gen2/*.zip

cmake/FindBoost.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Cache Variables
5555
include(FetchContent)
5656
string(REPLACE "." "_" "_boost_archive_version_component" "${Boost_FIND_VERSION}")
5757
set(boost_localinstall_root ${CMAKE_SOURCE_DIR}/stm32-tools/boost-${_boost_archive_version_component})
58-
set(boost_archive_root "https://boostorg.jfrog.io/artifactory/main/release")
58+
set(boost_archive_root "https://archives.boost.io/release")
5959
set(boost_archive_url "${boost_archive_root}/${Boost_FIND_VERSION}/source/boost_${_boost_archive_version_component}.zip")
6060
FetchContent_Declare(Boost
6161
PREFIX "${boost_localinstall_root}"

stm32-modules/flex-stacker/firmware/motor_control/motor_hardware.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ void motor_hardware_gpio_init(void){
127127
init.Pin = Z_STEP_PIN;
128128
HAL_GPIO_Init(Z_STEP_PORT, &init);
129129

130-
init.Pin = MOTOR_DIAG0_PIN;
131-
HAL_GPIO_Init(MOTOR_DIAG0_PORT, &init);
132-
133130
// X MOTOR
134131
init.Pin = X_EN_PIN;
135132
HAL_GPIO_Init(X_EN_PORT, &init);
@@ -410,6 +407,11 @@ bool hw_read_estop(void) {
410407
_motor_hardware.estop.active_setting;
411408
}
412409

410+
bool hw_read_diag0(void) {
411+
// diag0 is shared by all motors
412+
return HAL_GPIO_ReadPin(MOTOR_DIAG0_PORT, MOTOR_DIAG0_PIN) == GPIO_PIN_SET;
413+
}
414+
413415
void hw_set_diag0_irq(bool enable) {
414416
enable ?
415417
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn) :

stm32-modules/flex-stacker/firmware/motor_control/motor_policy.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "firmware/motor_policy.hpp"
22

3+
#include "FreeRTOS.h"
34
#include "firmware/motor_hardware.h"
5+
#include "task.h"
46

57
using namespace motor_policy;
68

@@ -50,6 +52,9 @@ auto MotorPolicy::set_diag0_irq(bool enable) -> void {
5052
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
5153
auto MotorPolicy::check_estop() -> bool { return hw_read_estop(); }
5254

55+
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
56+
auto MotorPolicy::check_diag0() -> bool { return hw_read_diag0(); }
57+
5358
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
5459
auto MotorPolicy::is_diag0_pin(uint16_t pin) -> bool {
5560
return hw_is_diag0_pin(pin);
@@ -58,4 +63,9 @@ auto MotorPolicy::is_diag0_pin(uint16_t pin) -> bool {
5863
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
5964
auto MotorPolicy::is_estop_pin(uint16_t pin) -> bool {
6065
return hw_is_estop_pin(pin);
61-
}
66+
}
67+
68+
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
69+
auto MotorPolicy::sleep_ms(uint32_t ms) -> void {
70+
vTaskDelay(pdMS_TO_TICKS(ms));
71+
}

stm32-modules/include/common/firmware/freertos_message_queue.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ class FreeRTOSMessageQueue {
4545
-> FreeRTOSMessageQueue = delete;
4646
~FreeRTOSMessageQueue() = default;
4747
[[nodiscard]] auto try_send(const Message& message,
48-
const uint32_t timeout_ticks = 0) -> bool {
49-
auto sent = xQueueSendToBack(queue, &message, timeout_ticks) == pdTRUE;
50-
return sent;
48+
const uint32_t timeout_ticks = 0,
49+
const bool to_front = false) -> bool {
50+
auto sent = (to_front)
51+
? xQueueSendToFront(queue, &message, timeout_ticks)
52+
: xQueueSendToBack(queue, &message, timeout_ticks);
53+
return sent == pdTRUE;
5154
}
5255

5356
[[nodiscard]] auto try_send_from_isr(const Message& message) -> bool {

stm32-modules/include/flex-stacker/firmware/motor_hardware.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ bool hw_read_limit_switch(MotorID motor_id, bool direction);
2424
void hw_set_diag0_irq(bool enable);
2525
bool hw_read_platform_sensor(bool direction);
2626
bool hw_read_estop(void);
27+
bool hw_read_diag0(void);
2728
bool hw_is_diag0_pin(uint16_t pin);
2829
bool hw_is_estop_pin(uint16_t pin);
2930

stm32-modules/include/flex-stacker/firmware/motor_interrupt.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,20 @@ class MotorInterruptController {
101101
auto limit_switch_triggered() -> bool {
102102
return _policy->check_limit_switch(_id, _direction);
103103
}
104+
104105
[[nodiscard]] auto get_response_id() const -> uint32_t {
105106
return _response_id;
106107
}
107108
auto stop_condition_met() -> bool {
108109
if (_stop) {
109110
return true;
110111
}
112+
if (_policy->check_estop()) {
113+
return true;
114+
}
115+
if (!_policy->check_diag0()) {
116+
return true;
117+
}
111118
if (_profile.movement_type() == motor_util::MovementType::OpenLoop) {
112119
return limit_switch_triggered();
113120
}

stm32-modules/include/flex-stacker/firmware/motor_policy.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ class MotorPolicy {
1818
auto set_diag0_irq(bool enable) -> void;
1919
auto check_platform_sensor(bool direction) -> bool;
2020
auto check_estop() -> bool;
21+
auto check_diag0() -> bool;
2122
auto is_diag0_pin(uint16_t pin) -> bool;
2223
auto is_estop_pin(uint16_t pin) -> bool;
24+
auto sleep_ms(uint32_t ms) -> void;
2325
};
24-
2526
} // namespace motor_policy

stm32-modules/include/flex-stacker/flex-stacker/gcodes.hpp

+31-9
Original file line numberDiff line numberDiff line change
@@ -252,46 +252,68 @@ struct GetDoorClosed {
252252
}
253253
};
254254

255-
struct SetStatusBarColor {
255+
struct SetStatusBarState {
256256
std::optional<StatusBarID> bar_id;
257257
std::optional<StatusBarColor> color;
258+
std::optional<StatusBarPattern> pattern;
259+
std::optional<uint32_t> duration;
260+
std::optional<int8_t> reps;
258261
float power;
259262

260-
using ParseResult = std::optional<SetStatusBarColor>;
263+
using ParseResult = std::optional<SetStatusBarState>;
261264
static constexpr auto prefix = std::array{'M', '2', '0', '0', ' '};
262265
static constexpr const char* response = "M200 OK\n";
263266

264267
using PowerArg = Arg<float, 'P'>;
265268
using ColorArg = Arg<uint8_t, 'C'>;
266-
using KArg = Arg<uint8_t, 'K'>;
269+
using KindArg = Arg<uint8_t, 'K'>;
270+
using PatternArg = Arg<uint8_t, 'A'>;
271+
using DurationArg = Arg<uint32_t, 'D'>;
272+
using RepsArg = Arg<int8_t, 'R'>;
267273

268274
template <typename InputIt, typename Limit>
269275
requires std::forward_iterator<InputIt> &&
270276
std::sized_sentinel_for<Limit, InputIt>
271277
static auto parse(const InputIt& input, Limit limit)
272278
-> std::pair<ParseResult, InputIt> {
273-
auto res = gcode::SingleParser<PowerArg, ColorArg, KArg>::parse_gcode(
274-
input, limit, prefix);
279+
auto res =
280+
gcode::SingleParser<PowerArg, ColorArg, KindArg, PatternArg,
281+
DurationArg, RepsArg>::parse_gcode(input, limit,
282+
prefix);
275283
if (!res.first.has_value()) {
276284
return std::make_pair(ParseResult(), input);
277285
}
278286

279-
auto ret = SetStatusBarColor{
280-
.bar_id = std::nullopt, .color = std::nullopt, .power = 0};
287+
auto ret = SetStatusBarState{.bar_id = std::nullopt,
288+
.color = std::nullopt,
289+
.pattern = std::nullopt,
290+
.duration = std::nullopt,
291+
.reps = std::nullopt,
292+
.power = 0};
281293

282294
auto arguments = res.first.value();
283295
if (std::get<0>(arguments).present) {
284296
ret.power = static_cast<float>(std::get<0>(arguments).value);
285297
}
286-
287298
if (std::get<1>(arguments).present) {
288299
ret.color =
289300
static_cast<StatusBarColor>(std::get<1>(arguments).value);
290301
}
291-
292302
if (std::get<2>(arguments).present) {
293303
ret.bar_id = static_cast<StatusBarID>(std::get<2>(arguments).value);
294304
}
305+
if (std::get<3>(arguments).present) {
306+
ret.pattern =
307+
static_cast<StatusBarPattern>(std::get<3>(arguments).value);
308+
}
309+
if (std::get<4>(arguments).present) {
310+
ret.duration = static_cast<float>(std::get<4>(arguments).value);
311+
}
312+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
313+
if (std::get<5>(arguments).present) {
314+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
315+
ret.reps = static_cast<int8_t>(std::get<5>(arguments).value);
316+
}
295317
return std::make_pair(ret, res.second);
296318
}
297319

stm32-modules/include/flex-stacker/flex-stacker/host_comms_task.hpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ class HostCommsTask {
5050
gcode::GetLimitSwitches, gcode::SetMicrosteps, gcode::GetMoveParams,
5151
gcode::SetMotorStallGuard, gcode::GetMotorStallGuard, gcode::HomeMotor,
5252
gcode::GetPlatformSensors, gcode::GetDoorClosed, gcode::GetEstopStatus,
53-
gcode::StopMotor, gcode::GetResetReason, gcode::SetStatusBarColor,
53+
gcode::StopMotor, gcode::GetResetReason, gcode::SetStatusBarState,
5454
gcode::GetTOFSensorStatus, gcode::GetTOFRegister, gcode::SetTOFRegister,
5555
gcode::EnableTOFSensor>;
56-
using AckOnlyCache = AckCache<
57-
8, gcode::EnterBootloader, gcode::SetSerialNumber,
58-
gcode::SetTMCRegister, gcode::SetRunCurrent, gcode::SetHoldCurrent,
59-
gcode::EnableMotor, gcode::DisableMotor, gcode::MoveMotorInSteps,
60-
gcode::MoveToLimitSwitch, gcode::MoveMotorInMm, gcode::SetMicrosteps,
61-
gcode::SetMotorStallGuard, gcode::HomeMotor, gcode::StopMotor,
62-
gcode::SetStatusBarColor, gcode::SetTOFRegister, gcode::EnableTOFSensor>;
56+
using AckOnlyCache =
57+
AckCache<8, gcode::EnterBootloader, gcode::SetSerialNumber,
58+
gcode::SetTMCRegister, gcode::SetRunCurrent,
59+
gcode::SetHoldCurrent, gcode::EnableMotor, gcode::DisableMotor,
60+
gcode::MoveMotorInSteps, gcode::MoveToLimitSwitch,
61+
gcode::MoveMotorInMm, gcode::SetMicrosteps,
62+
gcode::SetStatusBarState, gcode::SetMotorStallGuard,
63+
gcode::HomeMotor, gcode::StopMotor, gcode::SetTOFRegister,
64+
gcode::EnableTOFSensor>;
6365
using GetSystemInfoCache = AckCache<8, gcode::GetSystemInfo>;
6466
using GetTMCRegisterCache = AckCache<8, gcode::GetTMCRegister>;
6567
using GetLimitSwitchesCache = AckCache<8, gcode::GetLimitSwitches>;
@@ -1049,19 +1051,22 @@ class HostCommsTask {
10491051
template <typename InputIt, typename InputLimit>
10501052
requires std::forward_iterator<InputIt> &&
10511053
std::sized_sentinel_for<InputLimit, InputIt>
1052-
auto visit_gcode(const gcode::SetStatusBarColor& gcode, InputIt tx_into,
1054+
auto visit_gcode(const gcode::SetStatusBarState& gcode, InputIt tx_into,
10531055
InputLimit tx_limit) -> std::pair<bool, InputIt> {
10541056
auto id = ack_only_cache.add(gcode);
10551057
if (id == 0) {
10561058
return std::make_pair(
10571059
false, errors::write_into(tx_into, tx_limit,
10581060
errors::ErrorCode::GCODE_CACHE_FULL));
10591061
}
1060-
auto message = messages::SetStatusBarColorMessage{
1062+
auto message = messages::SetStatusBarStateMessage{
10611063
.id = id,
10621064
.bar_id = gcode.bar_id,
1063-
.power = gcode.power,
10641065
.color = gcode.color,
1066+
.pattern = gcode.pattern,
1067+
.duration = gcode.duration,
1068+
.reps = gcode.reps,
1069+
.power = gcode.power,
10651070
};
10661071
if (!task_registry->send(message, TICKS_TO_WAIT_ON_SEND)) {
10671072
auto wrote_to = errors::write_into(

stm32-modules/include/flex-stacker/flex-stacker/messages.hpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,18 @@ struct GetEstopResponse {
281281
bool triggered;
282282
};
283283

284-
struct SetStatusBarColorMessage {
284+
struct UpdateUIMessage {
285+
// Empty struct
286+
};
287+
288+
struct SetStatusBarStateMessage {
285289
uint32_t id = 0;
286290
std::optional<StatusBarID> bar_id = std::nullopt;
287-
std::optional<float> power = std::nullopt;
288291
std::optional<StatusBarColor> color = std::nullopt;
292+
std::optional<StatusBarPattern> pattern = std::nullopt;
293+
std::optional<uint32_t> duration = std::nullopt;
294+
std::optional<int8_t> reps = std::nullopt;
295+
std::optional<float> power = std::nullopt;
289296
};
290297

291298
struct GetTOFSensorStatusMessage {
@@ -342,7 +349,8 @@ using SystemMessage =
342349
SetSerialNumberMessage, EnterBootloaderMessage,
343350
GetDoorClosedMessage, GetResetReasonMessage>;
344351

345-
using UIMessage = ::std::variant<std::monostate, SetStatusBarColorMessage>;
352+
using UIMessage =
353+
::std::variant<std::monostate, UpdateUIMessage, SetStatusBarStateMessage>;
346354

347355
using MotorDriverMessage =
348356
::std::variant<std::monostate, SetTMCRegisterMessage, GetTMCRegisterMessage,

stm32-modules/include/flex-stacker/flex-stacker/motor_driver_task.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace motor_driver_task {
2626
using Message = messages::MotorDriverMessage;
2727

2828
static constexpr tmc2160::TMC2160RegisterMap motor_z_config{
29-
.gconfig = {.diag0_error = 0, .diag0_stall = 0},
29+
.gconfig = {.diag0_error = 0, .diag0_stall = 1},
3030
.short_conf = {.s2vs_level = 0x6,
3131
.s2g_level = 0x6,
3232
.shortfilter = 1,
@@ -45,7 +45,7 @@ static constexpr tmc2160::TMC2160RegisterMap motor_z_config{
4545
.hend = 0b11,
4646
.tbl = 0b1,
4747
.mres = 0b100},
48-
.coolconf = {.semin = 0b11, .semax = 0b100, .sgt = 1},
48+
.coolconf = {.semin = 0b11, .semax = 0b100, .sgt = 2},
4949
.pwmconf = {.pwm_ofs = 0x1F,
5050
.pwm_grad = 0x18,
5151
.pwm_autoscale = 1,
@@ -55,7 +55,7 @@ static constexpr tmc2160::TMC2160RegisterMap motor_z_config{
5555
};
5656

5757
static constexpr tmc2160::TMC2160RegisterMap motor_x_config{
58-
.gconfig = {.diag0_error = 0, .diag0_stall = 0},
58+
.gconfig = {.diag0_error = 0, .diag0_stall = 1},
5959
.short_conf = {.s2vs_level = 0x6,
6060
.s2g_level = 0x6,
6161
.shortfilter = 1,
@@ -74,7 +74,7 @@ static constexpr tmc2160::TMC2160RegisterMap motor_x_config{
7474
.hend = 0b1001,
7575
.tbl = 0b1,
7676
.mres = 0b100},
77-
.coolconf = {.semin = 0b11, .semax = 0b100, .sgt = 1},
77+
.coolconf = {.semin = 0b11, .semax = 0b100, .sgt = 2},
7878
.pwmconf = {.pwm_ofs = 0x1F,
7979
.pwm_grad = 0x18,
8080
.pwm_autoscale = 1,
@@ -84,7 +84,7 @@ static constexpr tmc2160::TMC2160RegisterMap motor_x_config{
8484
};
8585

8686
static constexpr tmc2160::TMC2160RegisterMap motor_l_config{
87-
.gconfig = {.diag0_error = 0, .diag0_stall = 0},
87+
.gconfig = {.diag0_error = 0, .diag0_stall = 1},
8888
.short_conf = {.s2vs_level = 0x6,
8989
.s2g_level = 0x6,
9090
.shortfilter = 1,
@@ -103,7 +103,7 @@ static constexpr tmc2160::TMC2160RegisterMap motor_l_config{
103103
.hend = 0b1001,
104104
.tbl = 0b1,
105105
.mres = 0b100},
106-
.coolconf = {.semin = 0b11, .semax = 0b100, .sgt = 1},
106+
.coolconf = {.semin = 0b11, .semax = 0b100, .sgt = 2},
107107
.pwmconf = {.pwm_ofs = 0x1F,
108108
.pwm_grad = 0x18,
109109
.pwm_autoscale = 1,

0 commit comments

Comments
 (0)