This repository was archived by the owner on Nov 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmicro-ROS-HB.sh
More file actions
executable file
·163 lines (140 loc) · 5.64 KB
/
Copy pathmicro-ROS-HB.sh
File metadata and controls
executable file
·163 lines (140 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#Check if the radio is set-up
FILE=/boot/overlays/mrf24j40ma.dtbo
if [ -f "$FILE" ]; then
RADIO_AVAILABLE="TRUE" #Radio available
RADIO_READY="FALSE"
else
#Radio and 6lowpan stack is not installed
echo "6LoWPAN communication and the MRF24J40 is not installed."
echo "If you don't install it, you won't have 6LoWPAN communication"
read -n 1 -p "Do you want to install it? (Y/N): " VAR
if [ $VAR == "y" ]; then
#Installing MRF24J40 radio and setting up the 6lowpan stack.
echo "Installing Dependencies\n"
sudo apt-get update
sudo apt install device-tree-compiler git -y
echo "Creating device tree for MRF24J40 radio and compiling it"
#Why I can't tab this??
cat <<EOF >mrf24j40ma-overlay.dts
/dts-v1/;
/plugin/;
/ {
compatible = "bcrm,bcm2835", "bcrm,bcm2836", "bcrm,bcm2708", "bcrm,bcm2709";
fragment@0 {
target = <&spi0>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
mrf24j40@0 {
compatible = "mrf24j40";
reg = <0>;
interrupts = <23 8>;
interrupt-parent = <&gpio>;
spi-max-frequency = <5000000>;
};
spidev@0 {
status = "disabled";
};
spidev@1 {
status = "disabled";
};
};
};
};
EOF
dtc -@ -O dtb -o mrf24j40ma.dtbo mrf24j40ma-overlay.dts
sudo cp mrf24j40ma.dtbo /boot/overlays/.
echo "Adding MRF24J40ma to system initialization"
sudo mv /boot/config.txt /boot/config_cpy.txt #Do a secutiry copy of the config file
touch config.txt
printf "dtparam=spi=on\ndtoverlay=mrf24j40ma\n" > config.txt
sudo cp config.txt /boot #Copy the new config file
rm config.txt
echo "Installing WPAN tools"
git clone https://github.com/linux-wpan/wpan-tools
sudo apt -y install dh-autoreconf libnl-3-dev libnl-genl-3-dev
cd wpan-tools
sudo ./autogen.sh
sudo ./configure CFLAGS='-g -O0' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
sudo make
sudo make install
#The radio and the stack is ready, now is necessary to reboot
clear
read -n 1 -p "The Raspberry Pi will reboot now. After the reboot Micro-ROS Hardware Bridge will be ready to work, just re-open the script. Press any key to continue"
#Configure the radio
sudo reboot
else
#6LoWPAN is not available
clean
echo "6LoWPAN communication won't be available"
RADIO_AVAILABLE="FALSE"
fi
fi
#Check if the folder Lowpan exists. If it didn't exit means that the network is not up.
FILE_LOWPAN=/sys/class/net/lowpan0
if [ $RADIO_AVAILABLE == "TRUE" ] && [ ! -e "$FILE_LOWPAN" ];
then
#Setting up the 6lowpan network
echo "Bringing up the network"
sudo iwpan dev wpan0 set pan_id 0xabcd
sudo iwpan phy phy0 set channel 0 26
sudo ip link add link wpan0 name lowpan0 type lowpan
sudo ip link set wpan0 up
sudo ip link set lowpan0 up
sudo ip -6 route delete fe80::/64 dev wlan0 proto kernel metric 256 pref medium
sudo ip -6 route delete fe80::/64 dev eth0 proto kernel metric 256 pref medium
RADIO_READY="TRUE"
fi
echo "Source micro-ROS Agent"
source micro-ros_cc_ws/install/setup.bash #Change to the right folder
UROS_FOLDER=micro-ros_cc_ws/build/micro_ros_agent #Change to the right folder
clear
# Show the information of the 6LoWPAN connection
ifconfig lowpan0
options=("Add new 6LoWPAN micro-ROS device" "Create UDP 6LoWPAN micro-ROS Agent" "Create UDP micro-ROS Agent"
"Create TCP micro-ROS Agent" "Create Serial micro-ROS Agent server" "Quit")
select opt in "${options[@]}"
do
case $opt in
"Add new 6LoWPAN micro-ROS device")
#Due to the problemes with the incompabilities between the Linux and NuttX and 6LoWPAN stack,
#is necessary to add manually a new device as neighbord
clear
read -n 39 -p "Please add the IPV6 of the new device: " CLIENT_IPV6
read -n 33 -p "Please add the MAC address of the new device: " CLIENT_ADDR
# TODO: Add custom MAC introduction.
sudo ip neigh add to $CLIENT_IPV6 dev lowpan0 lladdr $CLIENT_ADDR
echo "Added new device: $CLIENT_IPV6 with $CLIENT_ADDR MAC address "
;;
"Create UDP 6LoWPAN micro-ROS Agent")
clear
read -n 4 -p "Please type the port to use: " CLIENT_PORT
$UROS_FOLDER/micro_ros_agent udp6 --port $CLIENT_PORT &
;;
"Create UDP micro-ROS Agent")
clear
read -n 4 -p "Please type the port to use: " CLIENT_PORT
$UROS_FOLDER/micro_ros_agent udp4 --port $CLIENT_PORT &
;;
"Create TCP micro-ROS Agent")
clear
read -n 4 -p "Please type the port to use: " CLIENT_PORT
$UROS_FOLDER/micro_ros_agent tcp4 --port $CLIENT_PORT &
;;
"Create Serial micro-ROS Agent server")
clear
read -n 12 -p "Please add the route to the serial device: " CLIENT_PORT
if [ -e "$CLIENT_PORT" ]; then
$UROS_FOLDER/micro_ros_agent serial --dev $CLIENT_PORT &
else
echo "Device doesn't exist, please try again."
fi
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done