????????项目需求:机器人开机上电后工控机首先运行机械臂控制代码,再运行算法代码
gnome-session-properties
????????在弹出界面点击添加,名称随便填,命令填入要启动的脚本,注释随便填。
gnome-terminal -- /home/txz/start.sh
? ? ? ? 开机后首先ping机械臂的ip地址,每隔5s ping一次,能ping通后执行机械臂蜷缩操作命令,然后再打开一个终端窗口,启动算法代码。
#!/bin/bash
echo "$(date "+%Y-%m-%d %H:%M:%S") ceshila" >> /home/txz/screen.log
while true;do
if ping -c 1 10.7.5.18 &> /dev/null;then
echo "$(date "+%Y-%m-%d %H:%M:%S") Ping successul. Starting Python script."
echo "$(date "+%Y-%m-%d %H:%M:%S") Ping successful. Starting Python script." >> /home/txz/screen1.log
python3 /home/txz/arm_server/quansuo_position.py
sleep 3
python3 /home/txz/arm_server/quansuo_position.py
sleep 1
gnome-terminal -- /home/txz/8.17/401_serch-tcp_4/1_main_frame/build/test_demo
sleep 1
python3 /home/txz/arm_server/server_nano.py
break
else
echo "$(date "+%Y-%m-%d %H:%M:%S") Ping unsuccessful.Retrying in 5 seconds."
echo "$(date "+%Y-%m-%d %H:%M:%S") Ping unsuccessful.Retrying in 5 seconds." >> /home/txz/screen2.log
sleep 5
fi
done
? ? ? ? 找到开机启动的代码命令,然后kill掉,再让机械臂恢复零位
#!/bin/bash
# 查询命令的ID
command_name="python3" # 替换为你要查询的命令名称
command_pid=$(pgrep "$command_name")
if [ -z "$command_pid" ]; then
echo "未找到运行的命令: $command_name"
else
echo "找到运行的命令: $command_name (PID: $command_pid)"
# 杀死命令
kill -9 "$command_pid"
echo "已杀死命令: $command_name (PID: $command_pid)"
fi
python3 /home/txz/arm_server/zero_position.py
sleep 3
python3 /home/txz/arm_server/zero_position.py