Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
44ae447
add cppcrc
GrayHoang May 22, 2026
f1367a8
protobuf changes for fault messaging
GrayHoang May 22, 2026
f59fa1e
gpio resources
GrayHoang May 22, 2026
ba6ac9e
stspin motor controller implementation
GrayHoang May 22, 2026
d0a59a3
motor.h and cpp edits
GrayHoang May 22, 2026
db6cb7f
remove gpio libraries
GrayHoang May 22, 2026
17769aa
spi utils
GrayHoang May 22, 2026
b90d380
thunderloop
GrayHoang May 22, 2026
915f2a1
make enum
GrayHoang May 23, 2026
6b05e6f
adjust tests
GrayHoang May 23, 2026
f2fcb94
trinamics
GrayHoang May 23, 2026
a159d61
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 23, 2026
bb45e94
embedded BUILD file
GrayHoang May 23, 2026
9448109
Merge branch 'motor_driver_integration' of github.com:GrayHoang/Softw…
GrayHoang May 23, 2026
22870e8
fix ansible BUILD
GrayHoang May 23, 2026
fac0ace
docs and motor_index
GrayHoang May 23, 2026
778cfca
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mot…
GrayHoang May 23, 2026
fe4ce55
various fixes
GrayHoang May 23, 2026
4f7df94
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 23, 2026
12a8d46
address comments
GrayHoang May 28, 2026
360577d
Merge branch 'master' of github.com:UBC-Thunderbots/Software into mot…
GrayHoang May 28, 2026
04e1808
merge conflict
GrayHoang May 28, 2026
5b6fd13
re-add constants
GrayHoang May 28, 2026
bd21717
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 28, 2026
294a028
link comments to issues
GrayHoang May 28, 2026
2b710cc
Merge branch 'motor_driver_integration' of github.com:GrayHoang/Softw…
GrayHoang May 28, 2026
8aaa525
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] May 28, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/useful-robot-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- [Robot Diagnostics](#robot-diagnostics)
- [For Just Diagnostics](#for-just-diagnostics)
- [For AI + Diagnostics](#for-ai--diagnostics)
- [Robot Auto Test](#robot-auto-test)
- [STSPIN Motor Controller Test](#stspin-motor-controller-test)
- [On Robot Commands](#on-robot-commands)
- [Systemd Services](#systemd-services)
- [Debugging Uart](#debugging-uart)
Expand Down Expand Up @@ -76,9 +76,10 @@ This will stop the current Systemd services, replace and restart them. Binaries
<b>This will trigger motor calibration meaning the wheels may spin. Please elevate the robot so the wheels are not touching the ground for proper calibration.</b>

```bash
bazel run //software/embedded/ansible:run_ansible --platforms=//toolchains/cc:robot -- --playbook deploy_robot_software.yml --hosts <robot_ip> --ssh_pass <robot_password>
bazel run //software/embedded/ansible:run_ansible --platforms=//toolchains/cc:robot --//software/embedded:motor_board=<motor_board> -- --playbook deploy_robot_software.yml --hosts <robot_ip> --ssh_pass <robot_password>
```

* <motor_board> is the type of motor driver board on the robot (either `STSPIN` or `TRINAMIC`)
* <robot_ip> is the IP address of the robot
* <robot_password> is the password of the `robot` user account

Expand Down Expand Up @@ -140,13 +141,13 @@ From Software/src

network_interface can be found with `ifconfig` commonly `wlp59s0` for wifi.

## Robot Auto Test
Runs the robot auto test fixture on a robot through Ansible, which tests the motor board and power board SPI and UART transfer respectively.
## STSPIN Motor Controller Test
Deploys the STSPIN Motor Controller Test binary onto a robot through Ansible.

From Software/src:

```bash
bazel run //software/embedded/ansible:run_ansible --platforms=//toolchains/cc:robot -- --playbook robot_auto_test_playbook.yml --hosts <robot_name> --ssh_pass <robot_password>
bazel run //software/embedded/ansible:run_ansible --platforms=//toolchains/cc:robot --//software/embedded:motor_board=STSPIN -- --playbook deploy_stspin_motor_controller_test.yml --hosts <robot_name> --ssh_pass <robot_password>
```

* replace the \<robot_ip\> with the actual ip address of the Raspberry Pi for the ssh connection.
Expand Down
7 changes: 7 additions & 0 deletions src/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ http_archive(
url = "https://github.com/analogdevicesinc/TMC-API/archive/0cd695fab6d43ceb121af4b8608e5d92b14e1ce9.tar.gz",
)

http_archive(
name = "cppcrc",
build_file = "@//extlibs:cppcrc.BUILD",
strip_prefix = "cppcrc-6360eee1c8966d32b2552ce156b135ec6a3235f1",
url = "https://github.com/DarrenLevine/cppcrc/archive/6360eee1c8966d32b2552ce156b135ec6a3235f1.zip",
)

##############################################
# Register our Toolchains
##############################################
Expand Down
9 changes: 9 additions & 0 deletions src/extlibs/cppcrc.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Description:
# A very small, fast, header-only, C++ library for generating CRCs
# https://github.com/DarrenLevine/cppcrc/tree/main

cc_library(
name = "cppcrc",
hdrs = ["cppcrc.h"],
visibility = ["//visibility:public"],
)
32 changes: 25 additions & 7 deletions src/proto/robot_status_msg.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ enum ErrorCode

enum MotorFault
{
/*********** TMC Faults ************/
// Refer to Trinamic 6100 datasheet for precise definitions of motor faults.
// https://trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC6100_datasheet_Rev1.00.pdf
// (Section 5.1, p22-23)
Expand All @@ -99,6 +100,21 @@ enum MotorFault
PHASE_W_SHORT_COUNTER_DETECTED = 12;
PHASE_W_SHORT_TO_GND_DETECTED = 13;
PHASE_W_SHORT_TO_VS_DETECTED = 14;

// TODO: #3749 Move this to its own proto.
/*********** STSPIN Faults ************/
NO_FAULT = 15;
DURATION = 16;
OVER_VOLT = 17;
UNDER_VOLT = 18;
OVER_TEMP = 19;
START_UP = 20;
SPEED_FDBK = 21;
OVER_CURR = 22;
SW_ERROR = 23;
SAMPLE_FAULT = 24;
OVERCURR_SW = 25;
DP_FAULT = 26;
}

message DriveUnit
Expand All @@ -113,13 +129,15 @@ message DriveUnit
/* Data from all four drive units and the dribbler */
message MotorStatus
{
DriveUnit front_left = 1;
DriveUnit front_right = 2;
DriveUnit back_left = 3;
DriveUnit back_right = 4;
DribblerStatus dribbler = 5;
Vector local_velocity = 6;
AngularVelocity angular_velocity = 7;
DriveUnit front_left = 1;
DriveUnit front_right = 2;
DriveUnit back_left = 3;
DriveUnit back_right = 4;
DribblerStatus dribbler = 5;
Vector local_velocity = 6;
AngularVelocity angular_velocity = 7;
Vector target_local_velocity = 8;
AngularVelocity target_angular_velocity = 9;
}

/* Data about the network connection with the robots, including network-derived values */
Expand Down
50 changes: 32 additions & 18 deletions src/software/embedded/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

package(default_visibility = ["//visibility:public"])

config_setting(
name = "build_trinamic",
flag_values = {
":motor_board": "TRINAMIC",
},
)

config_setting(
name = "build_stspin",
flag_values = {
":motor_board": "STSPIN",
},
)

string_flag(
name = "motor_board",
build_setting_default = "TRINAMIC",
values = [
"TRINAMIC",
"STSPIN",
],
)

cc_library(
name = "primitive_executor",
srcs = ["primitive_executor.cpp"],
Expand All @@ -19,6 +42,15 @@ cc_library(
],
)

cc_library(
name = "spi_utils",
srcs = ["spi_utils.cpp"],
hdrs = ["spi_utils.h"],
deps = [
"//software/logger",
],
)

cc_library(
name = "thunderloop",
srcs = ["thunderloop.cpp"],
Expand All @@ -38,24 +70,6 @@ cc_library(
],
)

cc_library(
name = "gpio",
srcs = [
"gpio_char_dev.cpp",
"gpio_sysfs.cpp",
],
hdrs = [
"gpio.h",
"gpio_char_dev.h",
"gpio_sysfs.h",
],
deps = [
"//software/logger",
"//software/logger:network_logger",
"//software/util/make_enum",
],
)

cc_binary(
name = "thunderloop_main",
srcs = ["thunderloop_main.cpp"],
Expand Down
2 changes: 1 addition & 1 deletion src/software/embedded/ansible/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ py_binary(
"//software/embedded:thunderloop_main",
"//software/embedded/linux_configs/pi:pi_files",
"//software/embedded/linux_configs/systemd:systemd_files",
"//software/embedded/motor_controller:stspin_motor_controller_test",
"//software/embedded/robot_diagnostics_cli:robot_diagnostics_cli_tar",
"//software/embedded/services:robot_auto_test",
"//software/power:powerloop_tar",
],
deps = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: Deploy stspin_motor_controller_test binary to robot
hosts: THUNDERBOTS_HOSTS

tasks:
- name: Log Robot ID
ansible.builtin.debug:
msg: "[Robot ID = {{ inventory_hostname }}]"
tags: always

- name: Deploy stspin_motor_controller_test binary
block:
- name: Stop Services
become: true
become_method: ansible.builtin.sudo
ansible.builtin.systemd:
name: "thunderloop.service"
masked: false
daemon_reload: true
state: stopped
tags: always

- name: Delete stspin_motor_controller_test binary under ~/thunderbots_binaries
ansible.builtin.file:
state: absent
path: ~/thunderbots_binaries/stspin_motor_controller_test
become_method: ansible.builtin.sudo
become: true
register: result

- name: Log where Ansible is searching
ansible.builtin.debug:
msg: "{{ ansible_search_path }}"
tags: always

- name: Sync Binary
ansible.posix.synchronize:
src: ../../motor_controller/stspin_motor_controller_test
dest: ~/thunderbots_binaries/
recursive: true
copy_links: true
tags: always

This file was deleted.

7 changes: 0 additions & 7 deletions src/software/embedded/constants/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "constants",
hdrs = [
"constants.h",
],
)

py_library(
name = "py_constants",
srcs = [":py_constants.py"],
Expand Down
11 changes: 0 additions & 11 deletions src/software/embedded/constants/constants.h

This file was deleted.

18 changes: 18 additions & 0 deletions src/software/embedded/gpio/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "gpio",
srcs = [
"gpio.cpp",
"gpio_char_dev.cpp",
],
hdrs = [
"gpio.h",
"gpio_char_dev.h",
],
deps = [
"//software/logger",
"//software/logger:network_logger",
"//software/util/make_enum",
],
)
21 changes: 21 additions & 0 deletions src/software/embedded/gpio/gpio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "software/embedded/gpio/gpio.h"

#include <chrono>
#include <thread>

bool Gpio::pollValue(GpioState state, std::chrono::milliseconds timeout_ms)
{
const auto start_time = std::chrono::steady_clock::now();
while (getValue() != state)
{
std::this_thread::sleep_for(std::chrono::microseconds(100));

const auto current_time = std::chrono::steady_clock::now();
const auto elapsed_time = current_time - start_time;
if (elapsed_time > timeout_ms)
{
return false;
}
}
return true;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <chrono>

#include "software/util/make_enum/make_enum.hpp"

MAKE_ENUM(GpioState, LOW, HIGH);
Expand All @@ -22,4 +24,15 @@ class Gpio
* Get the current state of the gpio
*/
virtual GpioState getValue() = 0;

/**
* Polls the GPIO until it reaches the requested state or a timeout occurs
*
* @param state The GPIO state to wait for
* @param timeout_ms Maximum wait duration in milliseconds
*
* @return true if the GPIO reached the requested state within the timeout,
* false if timed out before the GPIO reached the requested state
*/
bool pollValue(GpioState state, std::chrono::milliseconds timeout_ms);
};
Loading
Loading