Commit 7fef54e0 authored by chenyulei's avatar chenyulei

Add new file

parents
Pipeline #1027 canceled with stages
#!/bin/bash
# How to use: (only accept three params below)
# 1.start lv nodes and record lv rosbag(the number represents the recording time): ./run_ros.sh lv 10
# 2.only start lv node: ./run_ros.sh lv
# 3.only start all nodes: ./run_ros.sh jfx
# 4. stop all nodes: ./run_ros.sh stop
# 5. restart all nodes: ./run_ros.sh restart
function getpids(){
local res=`ps -ef | grep -v grep | grep $1 | sed 's/[ ][ ]*/ /g' | cut -d' ' -f8`
echo $res
}
function killpids(){
local res=`ps -ef | grep -v grep | grep $1 | sed 's/[ ][ ]*/ /g' | cut -d' ' -f2,8`
local arr=($res)
for i in ${!arr[@]}
do
if [ `expr $i % 2` -eq 0 ];then
`echo "123" | sudo -S kill -9 ${arr[$i]}`
echo "\tprocess \033[36m${arr[$i+1]}\033[0m killed\n"
fi
done
}
function stopapp(){
source /home/nvidia/catkin_ws/devel/setup.sh
rosnode list
rosnode kill --all
rosnode cleanup
`killall roslaunch`
echo "============ ALL ROS NODE HAS BEEN SHUTDOWN ============"
}
function startapp(){
echo "====== ROSNODE KILL ALL======"
rosnode kill --all
clear
sleep 2
echo "====== START ROSCORE ======"
cd /home/nvidia/catkin_ws/
roscore_logname="roscore-$(date +%Y%m%d)_$(date +%H%M%S).log"
nohup roscore > ../log/$roscore_logname 2>&1 &
sleep 3
echo "====== START PANDAR64 ROS NODES ======"
cd /home/nvidia/catkin_ws/
source devel/setup.bash
lidar_logname="lidar-$(date +%Y%m%d)_$(date +%H%M%S).log"
nohup roslaunch hesai_lidar hesai_lidar.launch > ../log/$lidar_logname 2>&1 &
echo "====== START CAMERA ROS NODES ======"
cd /home/nvidia/catkin_ws/
source devel/setup.bash
camera_logname="camera-$(date +%Y%m%d)_$(date +%H%M%S).log"
nohup roslaunch spinnaker_sdk_camera_driver node_acquisition.launch > ../log/$camera_logname 2>&1 &
if [ $1 == "jfx" ];then
echo "====== Start PROJECT ROS NODES ========"
cd /home/nvidia/catkin_ws/
source devel/setup.bash
rosproject_logname="project-$(date +%Y%m%d)_$(date +%H%M%S).log"
nohup roslaunch jfxrosperceiver project.launch > ../log/$rosproject_logname 2>&1 &
fi
echo -e "----------------------------------------------------------------------------\n\n"
sleep 4
if [ $2 != " " ];then
for j in 1 2 3; do
if [ $j == 1 ];then
sleep 4
rm -rf /home/nvidia/rosbag/*
fi
echo "++++++ RECORD ROSBAG(LV) $j TIMES ++++++"
record_rosbag $2 j
done
echo "RECORD ROSBAG IS FINISHED"
fi
}
function record_rosbag(){
mkdir -p /home/nvidia/rosbag
cd /home/nvidia/rosbag
rosbag_logname="rosbag-$(date +%Y%m%d)_$(date +%H%M%S).log"
nohup rosbag record --duration=$1 $(rostopic list | grep 'pandar$') $(rostopic list | grep 'compressed$') > ../log/$rosbag_logname 2>&1 &
tm="scale=1; $1/100" | bc
export tm=$(echo "scale=1; $1/100" | bc)
i=0
icon=''
arr=('|' '/' '-' '\\')
index=0
while [ $i -le 100 ]
do
index=`echo $i%4`
printf "[%-74s][%d%%][%c]\r" "$icon" "$i" "${arr[$index]}"
icon='#'$icon
((i++))
sleep $tm
done
echo
echo "++++++ RECORD ROSBAG(LV) $j TIMES OK ++++++"
sleep 3
save_path="/media/nvidia/Data/7-1/"
rosbag_name=$( ls | grep '.bag$')
rosbag info $rosbag_name
echo "++++++ SCP $rosbag_name TO $save_path(POINT 1-1) ++++++"
scp ./*.bag nvidia@10.50.108.1:$save_path
rm -rf ./*.bag
echo -e "\n"
}
MODE="start"
if [ $# -ge 1 ];then
MODE=$1
fi
clear
mkdir -p /home/nvidia/log
if [ $MODE == "stop" ];then
stopapp
echo "mec app stopped at " `date` >> /home/nvidia/log/rosstop.log
elif [ $MODE == "start" ];then
startapp $2 $3
echo "mec app started at " `date` >> /home/nvidia/log/rosstart.log
elif [ $MODE == "restart" ];then
stopapp
startapp $2 $3
echo "mec app restarted at " `date` >> /home/nvidia/log/rosrestart.log
else
echo "Unexpected param(start stop or restart)"
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment