add services

This commit is contained in:
Sem van der Hoeven
2023-05-09 12:48:18 +02:00
parent 7ff51fc904
commit 31f3959de4
9 changed files with 94 additions and 1 deletions

View File

32
drone_scripts/find_id.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
lidarserial=00000000001A
heightserial=369A378F3439
find_by_id(){
v=${1%:*}; p=${1#*:} # split vid:pid into 2 vars
v=${v#${v%%[!0]*}}; p=${p#${p%%[!0]*}} # strip leading zeros
grep -il "^PRODUCT=$v/$p" /sys/bus/usb/devices/*:*/uevent |
sed s,uevent,, |
xargs -r grep -r '^DEVNAME=' --include uevent
}
ids=$(find_by_id 0483:5740)
echo $ids
for device in $ids
do
id=$(echo $device | cut -d "=" -f 2)
serial=$(/bin/udevadm info --name=/dev/$id | grep SERIAL_SHORT | cut -d = -f 2)
echo "device "$id" has serial number "$serial
if [ $serial = $lidarserial ]
then
echo "LIDAR on port" $id
echo $id > /home/ubuntu/drone_conf/lidar.conf
elif [ $serial = $heightserial ]
then
echo "height sensor on port" $id
echo $id > /home/ubuntu/drone_conf/height.conf
else
echo "unknown serial number" $serial
fi
done

View File

@@ -0,0 +1,10 @@
#!/bin/bash
. /home/ubuntu/source_ros2.sh
SERIAL=$(cat /home/ubuntu/drone_conf/height.conf)
echo "serial port is "$SERIAL
echo ros2 run height height_reader --ros-args -p height_serial_port:=/dev/${SERIAL}
ros2 run height height_reader --ros-args -p height_serial_port:=/dev/${SERIAL} | tee /home/ubuntu/drone_log/height.log

10
drone_scripts/start_lidar.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
. /home/ubuntu/source_ros2.sh
SERIAL=$(cat /home/ubuntu/drone_conf/lidar.conf)
echo "serial port is "$SERIAL
echo ros2 run object_detection lidar_reader --ros-args -p lidar_serial_port:=/dev/${SERIAL}
ros2 run object_detection lidar_reader --ros-args -p lidar_serial_port:=/dev/${SERIAL} | tee /home/ubuntu/drone_log/lidar.log

1
get_usb_device_port.sh Normal file
View File

@@ -0,0 +1 @@
/bin/udevadm info --name=/dev/ttyACM0 | grep SERIAL_SHORT | cut -d = -f 2

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Service to start the script that sets the serial ports for the USB sensors
[Service]
Type=simple
Restart=on-failure
User=ubuntu
ExecStart=/home/ubuntu/drone_scripts/find_id.sh
WorkingDirectory=/home/ubuntu
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,14 @@
[Unit]
Description=Height sensor for drone running in ROS 2
After=drone_find_usb_devices.service
[Service]
Type=simple
Restart=on-failure
User=ubuntu
ExecStart=/home/ubuntu/drone_scripts/start_height_sensor.sh
Environment="HOME=root"
WorkingDirectory=/home/ubuntu
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,14 @@
[Unit]
Description=Height sensor for drone running in ROS 2
After=drone_find_usb_devices.service
[Service]
Type=simple
Restart=on-failure
User=ubuntu
ExecStart=/home/ubuntu/drone_scripts/start_lidar.sh
Environment="HOME=root"
WorkingDirectory=/home/ubuntu
[Install]
WantedBy=multi-user.target