Skip to content

Commit 2dda9ce

Browse files
Redis to TOML refactor (UBC-Thunderbots#3537)
* refactor all fo redis to toml * file path change * correct network interface * remove bazel dep for toml * update comment * remove redis from software tests and workflow * [pre-commit.ci lite] apply automatic fixes * remove generated file * remove 3 keys and their usages * remove keys * remove / from keys * remove normalize_key * tests for toml_config_client * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 0f64a4e commit 2dda9ce

29 files changed

Lines changed: 1811 additions & 553 deletions

.github/workflows/main.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,11 @@ jobs:
6969
runs-on: ubuntu-24.04
7070
steps:
7171
- uses: actions/checkout@v4
72-
- uses: ./.github/actions/environment-setup
7372

74-
- name: Install and start redis server
75-
run: |
76-
wget http://download.redis.io/redis-stable.tar.gz
77-
tar xvzf redis-stable.tar.gz >/dev/null
78-
cd redis-stable
79-
make >/dev/null
80-
make install >/dev/null
81-
redis-server --daemonize yes
82-
83-
- name: Stop redis server
73+
- name: Environment Setup
8474
run: |
85-
redis-cli shutdown
86-
75+
"${GITHUB_WORKSPACE}"/environment_setup/setup_software.sh
76+
8777
- name: Jetson Nano Build
8878
run: |
8979
cd src

docs/getting-started.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,26 @@ Where `<platform>` is the robot platform you are deploying to (`PI` or `NANO`),
376376
It is possible to run Thunderloop without having a fully-working robot. Using this mode is useful when testing features that don't require the power board or motors.
377377

378378
1. To run Thunderloop locally on your computer
379-
1. First, you must ensure that `redis` is installed. Installation instructions can be found [here](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/install-redis-on-linux/). The result of these installation directions will likely enable `redis-server` as a service that starts on boot. You may want to run `sudo systemctl disable redis-server` to prevent this.
380-
2. Next, run the command `redis-server` in a terminal.
381-
3. Set up the following required REDIS constants by running the following commands in the terminal:
382-
- `redis-cli set /robot_id "{robot_id}"` where `{robot_id}` is the robot's ID (e.g. `1`, `2`, etc.)
383-
- `redis-cli set /network_interface "{network_interface}"` where `{network_interface}` is one of the interfaces listed by `ip a`.
384-
- `redis-cli set /channel_id "{channel_id}"` where `{channel_id}` is the channel id of the robot (e.g. `1`, `2`, etc.)
385-
- `redis-cli set /kick_coeff "{kick_coeff}"` where `{kick_coeff}` is a calibrated kicking parameter. When running locally, this parameter doesn't matter so `0` is fine.
386-
- `redis-cli set /kick_constant "{kick_constant}"` where `{kick_constant}` is a calibrated kicking parameter. When running locally, this parameter doesn't matter so `0` is fine.
387-
- `redis-cli set /chip_pulse_width "{chip_pulse_width}"` where `{chip_pulse_width}` is a calibrated kicking parameter. When running locally, this parameter doesn't matter so `0` is fine.
388-
4. Now, run Thunderloop with the following command:
379+
1. Create a TOML configuration file in the opt/tbotspython directory with the following content (replace values as needed):
380+
```toml
381+
robot_id = "1"
382+
channel_id = "0"
383+
network_interface = "tbotswifi5"
384+
kick_constant = "0"
385+
kick_coeff = "0.0"
386+
chip_pulse_width = "0"
387+
battery_voltage = "0.0"
388+
current_draw = "0.0"
389+
cap_voltage = "0.0"
390+
```
391+
Where:
392+
- `robot_id` is the robot's ID (e.g. `1`, `2`, etc.)
393+
- `network_interface` is one of the interfaces listed by `ip a`.
394+
- `channel_id` is the channel id of the robot (e.g. `1`, `2`, etc.)
395+
- `kick_coeff` is a calibrated kicking parameter. When running locally, this parameter doesn't matter so `0` is fine.
396+
- `kick_constant` is a calibrated kicking parameter. When running locally, this parameter doesn't matter so `0` is fine.
397+
- `chip_pulse_width` is a calibrated kicking parameter. When running locally, this parameter doesn't matter so `0` is fine.
398+
2. Now, run Thunderloop with the following command:
389399
- `bazel run //software/embedded:thunderloop_main --//software/embedded:host_platform=LIMITED`
390400

391401
2. If you have a robot PC that doesn't have proper communication with the power or motor board, you can still run Thunderloop in a limited capacity to test software features (eg. networking).

docs/robot-software-architecture.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- [Tools](#tools)
1010
- [Ansible](#ansible)
1111
- [Systemd](#systemd)
12-
- [Redis](#redis)
12+
- [TOML Configuration](#toml-configuration)
1313
- [Thunderloop](#thunderloop)
1414

1515
<!--TOC-->
@@ -37,9 +37,9 @@ More commands available [here](useful-robot-commands.md#off-robot-commands)
3737

3838
[Systemd](https://www.freedesktop.org/wiki/Software/systemd/) allows us to have services which start as soon as we boot the robot, will automatically restart and are individually controllable. All services have the file {service}.service, which controls the configuration of that service. Our core service brought up by systemd is thunderloop. The thunderloop.service file can be seen [here](https://github.com/UBC-Thunderbots/Software/blob/master/src/software/embedded/linux_configs/systemd/thunderloop.service).
3939

40-
## Redis
40+
## TOML Configuration
4141

42-
[Redis](https://redis.io/docs/about/) is an in-memory key-value store. This allows us to share state between processes as well as modify values dynamically through the provided [cli](useful-robot-commands#redis). Values also persists between boots.
42+
Robot configuration is stored in a TOML file in home directory. This file contains both static configuration values and dynamic runtime values.
4343

4444
# Thunderloop
4545

docs/useful-robot-commands.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
- [On Robot Commands](#on-robot-commands)
2222
- [Systemd Services](#systemd-services)
2323
- [Debugging Uart](#debugging-uart)
24-
- [Redis](#redis)
2524

2625
<!--TOC-->
2726

@@ -63,14 +62,6 @@ flowchart TD
6362
`service thunderloop restart`)
6463
tloop_status --> |Running| tloop_logs(Check Thunderloop logs for errors
6564
`journalctl -fu thunderloop -n 300`)
66-
tloop_logs --> |No Errors| check_redis(Does `redis-cli get /network_interface` return 'wlan0' or 'tbots',
67-
and does `redis-cli get /channel_id` return '0'?)
68-
tloop_logs --> |Contains Errors| rip2("Fix errors or check errors with a lead")
69-
check_redis --> |No| update_redis("Update Redis constants by running:
70-
`redis-cli set /network_interface 'wlan0'` (for Nanos) OR `redis-cli set /network_interface 'tbots'` (for Pis)
71-
`redis-cli set /channel_id '0'`")
72-
check_redis --> |Yes| rip3(Check with a lead)
73-
update_redis --> tloop_restart
7465
tloop_restart --> tloop_status
7566
end
7667
```
@@ -256,36 +247,3 @@ If the serial_port is busy, screen will not launch and instead says `screen is t
256247
Powerloop uart communication is encoded so you can't read it from screen and will appear as a mix of foreign characters
257248

258249
Pressing the reset button once will send a status msg over its connected port. This is useful for sanity checking.
259-
260-
## Redis
261-
262-
Current redis keys that are used are available in `software/constants.h`. Official Documentation [here](https://redis.io/docs/manual/cli/).
263-
264-
<b>Values should be strings. For example `set \ROBOT_ID "0"`</b>
265-
266-
Redis repl can be accessed through the following command.
267-
268-
```bash
269-
redis-cli
270-
```
271-
272-
Other common commands (once inside redis repl):
273-
274-
```bash
275-
get <redis_key>
276-
set <redis_key> <value>
277-
```
278-
279-
To Exit:
280-
281-
```bash
282-
quit
283-
```
284-
285-
Alternative (without entering redis repl):
286-
287-
```bash
288-
redis-cli get <redis_key>
289-
redis-cli set <redis_key> <value>
290-
```
291-

src/MODULE.bazel

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,12 @@ use_repo(pybind11_configure, "pybind11")
9090
###########################################################################
9191
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
9292

93-
# Dep for cpp_redis
9493
http_archive(
95-
name = "tacopie",
96-
sha256 = "bbdebecdb68d5f9eb64170217000daf844e0aee18b8c4d3dd373d07efd9f7316",
97-
strip_prefix = "tacopie-master",
98-
url = "https://github.com/cylix/tacopie/archive/master.zip",
99-
)
100-
101-
# TODO(#3315): Used for on-robot value storage - deprecation soon
102-
http_archive(
103-
name = "cpp_redis",
104-
sha256 = "12a6fc86ba4ca3d4537a3eee82c094f385b8e03e283c664c976f16d421f17f7d",
105-
strip_prefix = "cpp_redis-fc2c43fa07e45e1ef0f77cbda6a240e7890ae5aa",
106-
urls = [
107-
"https://github.com/cpp-redis/cpp_redis/archive/fc2c43fa07e45e1ef0f77cbda6a240e7890ae5aa.zip",
108-
],
94+
name = "tomlplusplus",
95+
build_file = "@//extlibs:tomlplusplus.BUILD",
96+
sha256 = "8517f65938a4faae9ccf8ebb36631a38c1cadfb5efa85d9a72e15b9e97d25155",
97+
strip_prefix = "tomlplusplus-3.4.0",
98+
urls = ["https://github.com/marzer/tomlplusplus/archive/refs/tags/v3.4.0.tar.gz"],
10999
)
110100

111101
http_archive(

0 commit comments

Comments
 (0)