You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Installation for these varies from system to system. You can check if you have these installed by typing `{application} --version`
9
-
into the terminal and seeing if it lists a version, or if it throws an error instead. If you're using Linux (or have WSL
10
-
set up) a good place to start is checking if these tools are offered through your package management system (like apt or
11
-
snap).
8
+
This guide assumes that you have access to a Unix-like environment (i.e. Linux/WSL or MacOS). You can make this work in Windows, but it's not officially supported. If you'd like to get set up with WSL, see the **Setting up WSL** section later in this guide.
9
+
10
+
Installation for these prerequisites varies from system to system. You can check if you have these installed by typing `{application} --version` into the terminal and seeing if it lists a version, or if it throws an error instead. A good place to start is checking if these tools are offered through your package management system (like apt or snap).
12
11
- git
13
-
- This is used for source code management, and is **not** the same as GitHub. Installing git allows you to use
14
-
command-line tools to push and pull code from the GitHub repo.
12
+
- This is used for source code management, and is **not** the same as GitHub. Installing git allows you to use command-line tools to push and pull code from the GitHub repo.
15
13
- cmake
16
-
- You need a version >= 3.28. This is used for build automation: it keeps track of the project and generates "Makefiles"
17
-
to compile the code.
14
+
- You need a version >= 3.28. This is used for build automation: it keeps track of the project and generates "Makefiles" to compile the code.
18
15
- gcc and g++
19
-
- gcc and g++ are compilers for the C and C++ programming languages, respectively. They turn the program from a text form
20
-
to machine code that can be read and executed by the processor. They generate the executable files (`.exe` in Windows)
21
-
that can be run by the computer. If you install gcc this should also include g++, but it doesn't hurt to run `g++ --version`
22
-
after installation to check, just in case.
16
+
- gcc and g++ are compilers for the C and C++ programming languages, respectively. They turn the program from a text form to machine code that can be read and executed by the processor. They generate the executable files (`.exe` in Windows) that can be run by the computer. If you install gcc this should also include g++, but it doesn't hurt to run `g++ --version` after installation to check, just in case.
23
17
- make
24
-
- Not to be confused with CMake. This is used to **run** (not generate) Makefiles, which are files that give instructions
25
-
to the compiler on how to compile the project's source files into one executable file. Makefiles list the dependencies
26
-
that source files have on each other and what compilation commands should be run to successfully compile them.
18
+
- Not to be confused with CMake. This is used to **run** (not generate) Makefiles, which are files that give instructions to the compiler on how to compile the project's source files into one executable file. Makefiles list the dependencies that source files have on each other and what compilation commands should be run to successfully compile them.
27
19
28
20
## Using Git(Hub)
29
21
30
22
### Cloning the repo
31
23
1. Open the terminal and `cd` into the directory that you want to clone the project into.
32
-
2. Run the command `git clone https://github.com/Cyclone-Robosub/Propulsion_2024_CPP.git`
24
+
2. Run the command `git clone https://github.com/Cyclone-Robosub/Command_Interpreter.git`
33
25
34
26
### Pushing Code
35
27
1.**Make sure the unit tests pass!** If your code isn't yet complete, consider making a new test branch.
@@ -46,10 +38,7 @@ snap).
46
38
6. Close the text editor.
47
39
- Note: if you want to cancel the commit, delete your commit notes and then close the text editor.
48
40
7. Run the command `git push`
49
-
- You will need to enter credentials here. If you don't have a Personal Access Token (PAT) configured, you will probably
50
-
need to do so. You want a "classic" token. When prompted to authenticate, you'll type your username as your GitHub
51
-
username and your password as your PAT (**not** your password!). More information here:
- You may need to enter credentials here. If you don't have a Personal Access Token (PAT) configured, you will probably need to do so. You want a "classic" token. When prompted to authenticate, you'll type your username as your GitHub username and your password as your PAT (**not** your password!). More information here: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
53
42
54
43
### Pulling Code
55
44
1. In the terminal, navigate to the project directory.
@@ -72,57 +61,46 @@ snap).
72
61
### Project Structure
73
62
- Code that we write lives in `lib/`.
74
63
- Code that we write for unit testing (to make sure our code is correct) lives in `testing/`.
75
-
- Data that we use for calculations lives in `data/`.
76
-
- Other libraries that we use (like eigen) have their own directories as well, named correspondingly.
64
+
- Other libraries that we use have their own directories as well, named correspondingly.
77
65
- You'll make your own `build/` folder (see **"Using Cmake to Build Code"**)
78
66
-`CMakeLists.txt` and `README.md` (this file!) live on the same level as the directories listed above.
79
67
80
68
### Basic Terminal Commands
81
-
-`ls` or `dir`: These are for Unix (Linux or macOS) and Windows respectively. These list all the files and folders in
82
-
your current location, excluding hidden files.
83
-
-`cd {path}`: This means to **c**hange **d**irectory to the directory specified in `{path}`. Path can be either a
84
-
"relative" path or an "absolute" path.
85
-
- A relative path is a path defined from your current location. If you're used to a graphical file explorer, you can
86
-
think of this as all the folders and files that you can see from within whatever folder you're currently in.
87
-
- An absolute path is a path defined from the "root" (start) of the file system. If you're on a Unix system, this
88
-
looks like `/`. If you're on Windows, you'll recognise it as `C:\ `.
69
+
-`ls`: These are for Unix (Linux or macOS) and Windows respectively. These list all the files and folders in your current location, excluding hidden files.
70
+
- To see hidden files (like .gitignore), you can run `ls -A`
71
+
-`cd {path}`: This means to **c**hange **d**irectory to the directory specified in `{path}`. Path can be either a "relative" path or an "absolute" path.
72
+
- A relative path is a path defined from your current location. If you're used to a graphical file explorer, you can think of this as all the folders and files that you can see from within whatever folder you're currently in.
73
+
- An absolute path is a path defined from the "root" (start) of the file system. On a Unix system, this looks like `/`. If you're normally a Windows user, you'll recognise it as `C:\ `.
89
74
- There are a few "special" files: `.` means "the current directory" and `..` means "the directory one level above".
90
-
- For example, if you're in `/home/me/Documents/Cyclone_Robosub/`, then `.` is `/home/me/Documents/Cyclone_Robosub/`
91
-
and `..` is `/home/me/Documents/`.
75
+
- For example, if you're in `/home/me/Documents/Cyclone_Robosub/`, then `.` is `/home/me/Documents/Cyclone_Robosub/` and `..` is `/home/me/Documents/`.
92
76
- You can `cd` to these just like any other directory.
93
-
- For more help with terminal commands, check the Internet. Make sure that you specify your OS: the commands can be very
94
-
different depending on whether you're on a Unix system or a Windows machine.
95
-
- With C/C++ programming, a Unix system is generally preferred. If you're using Windows, strongly consider configuring
96
-
WSL or (if you'd like a full Linux environment and your computer can take the extra overhead) a Linux virtual machine.
97
-
See the details on this in **Troubleshooting**.
77
+
- For more help with terminal commands, check the Internet. Make sure that you specify your OS: the commands can be very different depending on whether you're on a Unix system or a Windows machine.
98
78
99
79
## Running
100
80
101
81
### Using CMake to Build Code
102
-
#### Build for the PI
82
+
#### Build for a Non-Pi machine (i.e. a regular computer)
103
83
1. Open the terminal and `cd` to the project root. If you run `ls` here, you should see folders with names `lib/`, `testing/`, etc.
104
84
2. Run `cmake -DMOCK_RPI=ON -B build`
105
85
3. Run `cd build`
106
86
4. Run `make`. You should get one executables: `propulsion_test`.
107
87
5. Run with `./propulsion_test`.
108
88
109
-
#### Build for Non-Pi (regular computers)
89
+
#### Build for a Pi
110
90
1. Open the terminal and `cd` to the project root. If you run `ls` here, you should see folders with names `lib/`, `testing/`, etc.
111
91
2. Run `cmake -B build`
112
92
3. Run `cd build`
113
-
4. Run `make`. You should get one executables: `propulsion_test`.
93
+
4. Run `make`. You should get one executable: `propulsion_test`.
114
94
5. Run with `./propulsion_test`.
115
95
116
96
### Running Unit Tests
117
97
> Before you push code to the repo, you should make sure that you pass all the unit tests. Here's how:
118
-
1. Follow the instructions above to build the code (Using CMake to build code)
98
+
1. Follow the instructions above to build the code (**"Using CMake to Build Code"**)
119
99
2. Run with `./propulsion_test`
120
-
3. Confirm that all tests pass (are green). If there are any failed (red) tests, check why they're failing and get them
121
-
fixed! If you get stuck, try using the debugger (see **Troubleshooting**).
100
+
3. Confirm that all tests pass (are green). If there are any failed (red) tests, check why they're failing and get them fixed! If you get stuck, try using the debugger (see **Troubleshooting**).
122
101
123
102
### Making Unit Tests
124
-
You should write your tests in the `testing/` folder, in the testing file that corresponds with the file or class that
125
-
you're testing.
103
+
You should write your tests in the `testing/` folder, in the testing file that corresponds with the file or class that you're testing.
the test should be called `CommandInterpreterTest`. `Test_Name` refers to the name of this specific test: for example, if
135
113
you are testing that you can execute a command, call it `ExecuteCommand`.
136
114
137
-
Inside the test, you can add assertions to check that the code is performing as expected. These will be evaluated to determine
138
-
if the test passes when it is run. These look like `ASSERT_EQ(val1, val2)` (determines whether `val1` is equal to `val1`),
139
-
`ASSERT_TRUE(val)` (determines whether `val` evaluates to `true` or not), etc. If no assertions are added, the test will
140
-
pass if it doesn't crash, and fail if it does (without checking if the code is working correctly or not).
115
+
Inside the test, you should add assertions to check that the code is performing as expected. These will be evaluated to determine if the test passes when it is run. These look like `ASSERT_EQ(val1, val2)` (determines whether `val1` is equal to `val1`),`ASSERT_TRUE(val)` (determines whether `val` evaluates to `true` or not), etc. If no assertions are added, the test will pass if it doesn't crash, and fail if it does (without checking if the code is working correctly or not). Other assertions exist as well, and you should reference GTest documentation to learn more about them (https://google.github.io/googletest/reference/assertions.html).
141
116
142
117
To run these tests, see **"Running Unit Tests"**
143
118
119
+
## Setting up WSL
120
+
WSL stands for Windows Subsystem for Linux. It's developed by Microsoft, and provides you with a Linux terminal environment for your Windows machine. In many ways, this gives you the best of both worlds: the convenience of a Linux filesystem and command interface while still letting you use an operating system that you're familiar with (although you miss out on the clout of being able to say "I'm a Linux user!").
121
+
122
+
It's not the same as daul-booting or a virtual machine (although those can be great options for gaining access to a Linux environment). WSL doesn't require you to restart your computer every time you want to change which environment your in, and doesn't have the same resource-intensive characteristics of virtual machines. However, you don't get access to a graphical Linux environment, and there are sometimes quirks with WSL (such as shortcut keymapping, among others).
123
+
124
+
You can find official WSL instructions here: https://learn.microsoft.com/en-us/windows/wsl/install
125
+
126
+
You can choose any Linux environment that you like, but the easiest option is Ubuntu or an Ubuntu-based distribution. The Raspberry Pis that our code runs on have Ubuntu installed, so running Ubunutu in WSL ensures the best compatibility.
127
+
128
+
Once it's set up, take some time to get used to the terminal environment. Try moving around to different folders, and explore a bit. The best way to learn is through experience!
129
+
144
130
## Troubleshooting
145
131
- When I try to turn `cmake -B build`, I get an error saying that my version of CMake is too old!
146
-
- The default version installed may be too old for this project. Try removing it (if in a Linux environment, this might
147
-
be `sudo apt remove cmake`) and installing it again, making sure that you're installing a version >= 3.28.
132
+
- The default version installed may be too old for this project. Try removing it (if in a Linux environment, this might be `sudo apt remove cmake`) and installing it again, making sure that you're installing a version $ \geq 3.28$.
148
133
- When I run `cmake -B build`, I get an error saying that it can't find my compiler!
149
134
- Double check that gcc/g++ and make are installed and can be run through the terminal.
150
135
- When I try to run git (i.e. `git pull`) I get an error saying "not a git repository"!
151
-
- Check that you're in a directory inside the project. This can be confirmed through the `ls` or `dir` command: make
152
-
sure that the files displayed match those of the project.
136
+
- Check that you're in a directory inside the project. This can be confirmed through the `ls` command: make sure that the files displayed match those of the project.
153
137
- I installed WSL, and I can't find my project files through the WSL command line!
154
-
- You'll almost certainly want to move your files into the Linux filesystem offered by WSL eventually, but until then
155
-
you can access your Windows filesystem from `/mnt/c` within WSL. Try running `cd /mnt/c` and then `ls`: this should
156
-
display a familiar-looking filesystem that you can navigate to find your project directory.
138
+
- You'll almost certainly want to move your files into the Linux filesystem offered by WSL eventually, but until then you can access your Windows filesystem from `/mnt/c` within WSL. Try running `cd /mnt/c` and then `ls`: this should display a familiar-looking filesystem that you can navigate to find your project directory.
157
139
- Help! My code is crashing / giving me a `SIGSEV` error / not passing the unit tests!
158
-
- Try using the debugger to find where and why your code is breaking! Your IDE probably offers built-in debugging tools.
159
-
Put a breakpoint where you'd like the code to stop (such as in a function call that you think is crashing), run the
160
-
code in debug mode, and then step through line by line from your breakpoint. Keep an eye on the values of the
161
-
variables: when one stops matching what you expect, or the program crashes, or both, see if you can work out why the
162
-
code doesn't match your expectations.
163
-
- I can't work out how to install the prerequisites I need in Windows!
164
-
- The Windows command interface can be really annoying and unintuitive. Consider giving WSL a try: it's quick and easy
165
-
to get set up, and gives you the convenience of a Linux filesystem and command interface while still letting you use an
166
-
operating system that you're familiar with (although you miss out on the clout of being able to say "I'm a Linux user!").
167
-
You can find instructions here: https://learn.microsoft.com/en-us/windows/wsl/install
140
+
- Try using the debugger to find where and why your code is breaking! Your IDE probably offers built-in debugging tools. Put a breakpoint where you'd like the code to stop (such as in a function call that you think is crashing), run the
141
+
code in debug mode, and then step through line by line from your breakpoint. Keep an eye on the values of the variables: when one stops matching what you expect, or the program crashes, or both, see if you can work out why the code doesn't match your expectations.
142
+
143
+
---
144
+
145
+
# User Resources
146
+
147
+
## Overview
148
+
Command_Interpreter is designed to run on a Raspberry Pi 5 (or 4). It is used to get commands from a main executive and send them to a Raspberry Pi Pico, which will set PWM values to control thruster speed and direction. This code won't run (outside of a testing build) unless it has a Raspberry Pi Pico attached via USB.
149
+
150
+
## Necessary Setup
151
+
To run this code, you must have WiringPi installed. Additionally, you will need to update the ID of the Rasberry Pi Pico in the `Command_Interpreter_Testing` and `Wiring.cpp` files to the corresponding name (found in `\dev\serial\by-id\`). The Pico should be running the code from the MicroPython Pool Testing repo (https://github.com/Cyclone-Robosub/micro-python-pool-test/).
152
+
153
+
## Command_Intepreter.*
154
+
These and `Command.h` are the only files that contains code that you should have to actively interact with. Functions should be heavily documented, so it is encouraged to hover over function names to see what parameters represent and how functions should be used.
155
+
156
+
A Command Interpreter object needs to be given thruster pins and digital pins (although these can be empty if a certain pin type is unused). Thruster pins are those that are to be used to signal to the robot thrusters, and can be either Hardware or Software PWM pins. If you're running off of a Pico (and you probably are), they should be Hardware PWM. Additionally, it needs to be a given three output streams: output, outLog, and errorLog. Output is where standard messages should be sent (you probably want this to be std::cout so that messages are sent to stdout), outLog is where you want standard logging messages to be sent, and errorLog is where you want error messages to be logged. These can be set to the same file if you want everything consolidated, or to `\dev\null` if you want them sent into the abyss.
157
+
158
+
Once a Command Interpreter is created, with the appropriate pins designated for thrusters and digital pins, execute commands can be sent through the execute functions. These commands will be relayed to the Pi Pico, which will set the corresponding pins to the specified PWM values.
159
+
160
+
## Command.h
161
+
This specifies the components of a command to be passed to the Command Interpreter. There are three componenents: acceleration, steady-state, and deceleration. The idea is that the command will bring the robot up to a certain velocity, then maintain that velocity for a certain amount of time, then decelerate back to stopped. PWMs and durations can be specified per each component. If the component is unnecessary (i.e. only a steady-state component is desired), then the other components should be set to a duration of $0$ and the PWMs set to the same values as the used component.
162
+
163
+
## Wiring.*
164
+
This contains code used internally by Command Interpreter to send commands over serial to the Pico. You shouldn't have to interface with this when using Command_Interpreter elsewhere.
168
165
169
166
---
170
167
171
-
Code by Propulsion subteam of UC Davis Cyclone Robosub. README by William Barber.
168
+
Code by Propulsion subteam of UC Davis Cyclone Robosub. README by William Barber.
0 commit comments