forked from tonynajjar/ros2-aliases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathros2_utils.bash
168 lines (147 loc) · 3.38 KB
/
ros2_utils.bash
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
164
165
166
167
168
#!/usr/bin/env bash
# Topics
function rtlist {
CMD="ros2 topic list"
echo $CMD
$CMD
history -s rtlist
history -s $CMD
}
function rtecho {
TOPIC=$(ros2 topic list | fzf)
CMD="ros2 topic echo $TOPIC"
echo $CMD
$CMD
history -s rtecho
history -s $CMD
}
function rtinfo {
TOPIC=$(ros2 topic list | fzf)
CMD="ros2 topic info -v $TOPIC"
echo $CMD
$CMD
history -s rtinfo
history -s $CMD
}
# Nodes
function rnlist {
CMD="ros2 node list"
echo $CMD
$CMD
history -s rnlist
history -s $CMD
}
function rninfo {
NODE=$(ros2 node list | fzf)
CMD="ros2 node info $NODE"
echo $CMD
$CMD
history -s rninfo
history -s $CMD
}
# Services
function rslist {
CMD="ros2 service list"
echo $CMD
$CMD
history -s rslist
history -s $CMD
}
# Parameters
function rplist {
NODE=$(ros2 node list | fzf)
CMD="ros2 param list $NODE --param-type"
echo $CMD
$CMD
history -s rplist
history -s $CMD
}
function rpget {
NODE=$(ros2 node list | fzf)
PARAM=$(ros2 param list $NODE | fzf)
CMD="ros2 param get $NODE $PARAM"
echo $CMD
$CMD
history -s rpget
history -s $CMD
}
function rpset {
NODE=$(ros2 node list | fzf)
PARAM=$(ros2 param list $NODE | fzf)
echo -n "value: "
read VALUE
CMD="ros2 param set $NODE $PARAM $VALUE"
echo $CMD
$CMD
history -s rpset
history -s $CMD
}
function rnkill {
NODE_TO_KILL_RAW=$(ros2 node list | fzf)
NODE_TO_KILL=(${NODE_TO_KILL_RAW//// })
NODE_TO_KILL=${NODE_TO_KILL[-1]} # extract last word from node name
NODE_TO_KILL=[${NODE_TO_KILL:0:1}]${NODE_TO_KILL:1}
# The method used is to parse the PID and use kill <PID>.
# If more than 1 PID is found, we abort to avoid killing other processes.
# The parsing checks for any process with the string [/]$NODE_TO_KILL.
# This can probably be optimized to always find the one node we are looking for.
PROC_NB=$(ps aux | grep [/]$NODE_TO_KILL | wc -l)
if [ $PROC_NB -gt 1 ]; then
echo "This node name matched with more than 1 process. Not killing"
return
elif [ $PROC_NB -eq 0 ]; then
echo "No processes found matching this node name"
return
fi
PROC_PID=$(ps aux | grep [/]$NODE_TO_KILL | awk '{print $2}')
CMD="kill $PROC_PID"
echo "Killing $NODE_TO_KILL_RAW with PID $PROC_PID"
$CMD
history -s rnlist
history -s $CMD
}
# TF
function view_frames {
if [ $# -eq 0 ]; then
REMAP=""
else
REMAP="--ros-args -r /tf:=/$1/tf -r /tf_static:=/$1/tf_static"
fi
CMD="ros2 run tf2_tools view_frames $REMAP"
echo $CMD
$CMD
history -s view_frames $@
history -s $CMD
}
function tf_echo {
if [ $# -eq 3 ]; then
REMAP="--ros-args -r /tf:=/$3/tf -r /tf_static:=/$3/tf_static"
else
REMAP=""
fi
CMD="ros2 run tf2_ros tf2_echo $1 $2 $REMAP"
echo $CMD
$CMD
history -s tf_echo $@
history -s $CMD
}
# Colcon
function cb {
if [ $# -eq 0 ]; then
CMD="colcon build --symlink-install"
else
CMD="colcon build --symlink-install --packages-select $@"
fi
echo $CMD
$CMD
history -s cb $@
history -s $CMD
}
# Rosdep
function rosdep_install {
CMD="rosdep install --from-paths src --ignore-src -r -y"
echo $CMD
$CMD
history -s rosdep_install
history -s $CMD
}