Work log 2023-08-29 - Change AD converter
2023-09-03

The Eel in the test tank

What did we do?

We created a new implementation of the distance sensor class where we use another AD converter called MCP3208 that uses SPI bus for communication instead of I2C. The idea is that the SPI bus is more resistant to magnetic disturbanses then the I2C bus, giving us a more robust system.

Learnings

  • Implementation was fairly straight forward and the module layout is working.
  • Issue with the sensors always returning the same value, after a lot of debugging we believe that it was related to permissions on the SPI-dev file.
  • Installed spidev.

Solution

1.Install spidev

https://www.youtube.com/watch?v=6VQIfGnMMt0

EDIT: pip install spidev is the way to go.

2. Change permissions and groups for the spi-dev.

sudo groupadd spiuser
sudo usermod -aG spiuser <yourusername>
sudo chown :spiuser <put the spi device name here>
sudo chmod g+rw <put the spi device name here>

EDIT: The following is another solution, that has been tested and that works.

#!/bin/bash

user=ubuntu
spi_rules_file_path=/etc/udev/rules.d/90-gpio-spi.rules

line1="KERNEL==\"spidev0.0\", OWNER=\"root\", GROUP=\"spi\""
line2="KERNEL==\"spidev0.1\", OWNER=\"root\", GROUP=\"spi\""

echo $line1 > $spi_rules_file_path
echo $line2 >> $spi_rules_file_path

echo "Wrote file $spi_rules_file_path"
cat $spi_rules_file_path

groupadd -f --system spi
usermod -a -G spi $user

echo "Created group spi and added user $user"
echo "All groups:"
groups $user
echo
echo "Remember to reboot!"
echo
echo "Done!"

3. Reboot

Reboot.

Notes

This way you can run the ROS nodes individually and it allows for easier logging.

ros2 run eel tank --ros-args -p simulate:=False -p cmd_topic:=/tank_front/cmd -p status_topic:=/tank_front/status -p motor_pin:=23 -p direction_pin:=18 -p tank_floor_value:=0.66 -p tank_ceiling_value:=0.16 -p distance_sensor_channel:=0
ros2 run eel tank --ros-args -p simulate:=False -p cmd_topic:=/tank_rear/cmd -p status_topic:=/tank_rear/status -p motor_pin:=24 -p direction_pin:=25 -p tank_floor_value:=0.288 -p tank_ceiling_value:=0.005 -p distance_sensor_channel:=1