Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial done better #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion ROS/osr_bringup/config/roboclaw_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ roboclaw_wrapper:
corner_acceleration_factor: 0.8 # fraction used to scale down the corner motor acceleration (0, 1])
velocity_timeout: 2.0 # maximum time [s] a particular velocity command will stay active without a new command before stopping
baud_rate: 115200
device: "/dev/serial1"
device: "/dev/serial0"
addresses: [128, 129, 130]
duty_mode: true # send duty commands to the roboclaw instead of velocity commands. This can mean a smoother drive but shouldn't be used for autonomous navigation as velocity commands aren't interpreted correclty
velocity_qpps_to_duty_factor: 8 # hand-tuned factor to convert velocity commands to duty commands, must be integer
Expand Down
7 changes: 0 additions & 7 deletions config/serial_udev_ubuntu.rules

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/roboclawtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
print(roboclaw0.ReadVersion(address))
print(roboclaw0.ReadEncM1(address))
elif connected1:
print("Connected to /dev/serial1.")
print("Connected to /dev/serial1. Only proceed if you know what you're doing, otherwise ask for help on Slack.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats this slack?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(roboclaw1.ReadVersion(address))
print(roboclaw1.ReadEncM1(address))
else:
Expand Down
39 changes: 6 additions & 33 deletions setup/rpi.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,43 +118,16 @@ The RPi talks to the motor controllers over serial bus.
sudo raspi-config
```

Then use the menu to enable **I2C** and **Serial** under `Interfaces`. More on raspi-config [here](https://www.raspberrypi.com/documentation/computers/configuration.html).
Then use the menu to enable **I2C** and **Serial** under `Interfaces`. When you enable `Serial Port`, it will ask:

**TIP**: If `raspi-config` isn't installed, run `sudo apt-get install raspi-config`. If that doesn't work, run `echo "deb http://archive.raspberrypi.org/debian/ buster main" >> /etc/apt/sources.list && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7FA3303E && sudo apt-get update` to allow `apt` to find the program, then try reinstalling with `sudo apt-get install raspi-config`.

### Disable [email protected]

**NOTE**: this section may no longer be necessary with newer versions of debian. We suggest skipping it and revisiting if serial does not work.
* Would you like a login shell to be accessible over serial? --> Select 'No' using the arrow keys and 'tab' and 'enter' keys on your keyboard
* Would you like the serial port hardware to be enabled? --> Yes

Because we are using the serial port for communicating with the roboclaw motor controllers, we have to disable the [email protected] service. This service has some level of control over serial devices that we use, so if we leave it on it we'll get weird errors ([source](https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3-4/)). Note that the masking step was suggested [here](https://stackoverflow.com/a/43633467/4292910). It seems to be necessary for some setups of the rpi4 - just using `systemctl disable` won't cut it for disabling the service.
If it asks you to reboot, answer 'yes'.

**Note that the following will stop you from being able to communicate with the RPi over the serial, wired connection. However, it won't affect communication with the rpi with SSH over wifi.**
More on raspi-config [here](https://www.raspberrypi.com/documentation/computers/configuration.html).

```
sudo systemctl stop [email protected]
sudo systemctl disable [email protected]
sudo systemctl mask [email protected]
```

### Copy udev rules

Now we'll need to copy over a udev rules file, which is used to automatically configure needed linux device files in `/dev` namely, `ttyS0 and ttyAMA0`. These are used to connect to the Roboclaws using the RPi's GPIO pins. Here's a [good primer](http://reactivated.net/writing_udev_rules.html) on udev.

```commandline
# copy udev file from the repo to your system
cd ~/osr_ws/src/osr-rover-code/config
sudo cp serial_udev_ubuntu.rules /etc/udev/rules.d/10-local.rules
```

and enter your password if requested.

Reload the udev rules so that the rules go into effect and the devices files are set up correctly.

```commandline
sudo udevadm control --reload-rules && sudo udevadm trigger
```

This configuration will persist across RPi reboots.
**TIP**: If `raspi-config` isn't installed, run `sudo apt-get install raspi-config`. If that doesn't work, run `echo "deb http://archive.raspberrypi.org/debian/ buster main" >> /etc/apt/sources.list && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7FA3303E && sudo apt-get update` to allow `apt` to find the program, then try reinstalling with `sudo apt-get install raspi-config`.

### Add user to tty and dialout groups

Expand Down