ROS常见问题(二) 运行文件时报错environment variable ' ###_MODEL' is not set

作者在配置pibot机器人时报错:

Invalid <arg> tag: environment variable 'PIBOT_MODEL' is not set.

Arg xml is <arg default="$(env PIBOT_MODEL)" doc="model type [apollo, zeus, hades, hera]" name="model"/>
The traceback for the exception was written to the log file

 

解决方案:

环境未配置

配置环境即可

./pibot_init_env.sh
source ~/.bashrc

 

其中,pibot_init_env.sh文件源码如下:

  1 #!/bin/bash
  2 
  3 if ! [ $PIBOT_ENV_INITIALIZED ]; then
  4     echo "export PIBOT_ENV_INITIALIZED=1" >> ~/.bashrc
  5     echo "source ~/.pibotrc" >> ~/.bashrc
  6 
  7     #rules
  8     echo "setup pibot modules"
  9     echo " "
 10     sudo cp rules/pibot.rules  /etc/udev/rules.d
 11     sudo cp rules/rplidar.rules  /etc/udev/rules.d
 12     sudo cp rules/ydlidar.rules  /etc/udev/rules.d
 13     sudo cp rules/orbbec.rules  /etc/udev/rules.d
 14     echo " "
 15     echo "Restarting udev"
 16     echo ""
 17     sudo service udev reload
 18     sudo service udev restart
 19 fi
 20 
 21 code_name=$(lsb_release -sc)
 22 
 23 if [ "$code_name" = "trusty" ]; then
 24     ros_version="indigo"
 25 elif [ "$code_name" = "xenial" ]; then
 26     ros_version="kinetic"
 27 else
 28     echo "PIBOT not support "$code_name
 29     exit
 30 fi 
 31 
 32 echo "source /opt/ros/${ros_version}/setup.bash" > ~/.pibotrc
 33 
 34 
 35 #LOCAL_IP=`ifconfig eth0|grep "inet addr:"|awk -F":" '{print $2}'|awk '{print $1}'`
 36 #LOCAL_IP=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}'`
 37 
 38 #if [ ! ${LOCAL_IP} ]; then
 39 #    echo "please check network"
 40 #    exit
 41 #fi
 42 
 43 LOCAL_IP=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | awk -F"/" '{print $1}'`
 44 echo "LOCAL_IP=\`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print \$2}' | awk -F"/" '{print \$1}'\`" >> ~/.pibotrc
 45 
 46 if [ ! ${LOCAL_IP} ]; then
 47     echo "please check network"
 48     exit
 49 fi
 50 
 51 read -p "please specify pibot model(0:apollo,1:apolloX,2:zeus,3:hera,4:hades,other for user defined):" PIBOT_MODEL_INPUT
 52 
 53 if [ "$PIBOT_MODEL_INPUT" = "0" ]; then
 54     PIBOT_MODEL='apollo'
 55 elif [ "$PIBOT_MODEL_INPUT" = "1" ]; then
 56     PIBOT_MODEL='apolloX'
 57 elif [ "$PIBOT_MODEL_INPUT" = "2" ]; then
 58     PIBOT_MODEL='zeus'
 59 elif [ "$PIBOT_MODEL_INPUT" = "3" ]; then
 60     PIBOT_MODEL='hera'
 61 elif [ "$PIBOT_MODEL_INPUT" = "4" ]; then
 62     PIBOT_MODEL='hades'
 63 else
 64     PIBOT_MODEL=$PIBOT_MODEL_INPUT 
 65 fi
 66 
 67 read -p "please specify your pibot lidar(0:rplidar,1:rplidar-a3,2:eai-x4,3:eai-g4,4:xtion,5:astra,6:kinectV1,other for user defined):" PIBOT_LIDAR_INPUT
 68 
 69 if [ "$PIBOT_LIDAR_INPUT" = "0" ]; then
 70     PIBOT_LIDAR='rplidar'
 71 elif [ "$PIBOT_LIDAR_INPUT" = "1" ]; then
 72     PIBOT_LIDAR='rplidar-a3'
 73 elif [ "$PIBOT_LIDAR_INPUT" = "2" ]; then
 74     PIBOT_LIDAR='eai-x4'
 75 elif [ "$PIBOT_LIDAR_INPUT" = "3" ]; then
 76     PIBOT_LIDAR='eai-g4'
 77 elif [ "$PIBOT_LIDAR_INPUT" = "4" ]; then
 78     PIBOT_LIDAR='xtion'
 79 elif [ "$PIBOT_LIDAR_INPUT" = "5" ]; then
 80     PIBOT_LIDAR='astra'
 81 elif [ "$PIBOT_LIDAR_INPUT" = "6" ]; then
 82     PIBOT_LIDAR='kinectV1'
 83 else
 84     PIBOT_LIDAR=$PIBOT_LIDAR_INPUT
 85 fi
 86 
 87 echo "export ROS_IP=\`echo \$LOCAL_IP\`" >> ~/.pibotrc
 88 echo "export ROS_HOSTNAME=\`echo \$LOCAL_IP\`" >> ~/.pibotrc
 89 echo "export PIBOT_MODEL=${PIBOT_MODEL}" >> ~/.pibotrc
 90 echo "export PIBOT_LIDAR=${PIBOT_LIDAR}" >> ~/.pibotrc
 91 
 92 read -p "please select specify the current machine(ip:$LOCAL_IP) type(0:onboard,other:remote):" PIBOT_MACHINE_VALUE
 93 if [ "$PIBOT_MACHINE_VALUE" = "0" ]; then
 94     ROS_MASTER_IP_STR="\`echo \$LOCAL_IP\`"
 95     ROS_MASTER_IP=`echo $LOCAL_IP`
 96 else
 97     read -p "plase specify the onboard machine ip for commnicationi:" PIBOT_ONBOARD_MACHINE_IP
 98     ROS_MASTER_IP_STR=`echo $PIBOT_ONBOARD_MACHINE_IP`
 99     ROS_MASTER_IP=`echo $PIBOT_ONBOARD_MACHINE_IP`
100 fi
101 
102 echo "export ROS_MASTER_URI=`echo http://${ROS_MASTER_IP_STR}:11311`" >> ~/.pibotrc
103 
104 echo "*****************************************************************"
105 echo "model: " $PIBOT_MODEL 
106 echo "lidar:" $PIBOT_LIDAR  
107 echo "local_ip: " ${LOCAL_IP} 
108 echo "onboard_ip:" ${ROS_MASTER_IP}
109 echo ""
110 echo "please execute source ~/.bashrc to make the configure effective"
111 echo "*****************************************************************"
112 
113 echo "source ~/pibot_ros/ros_ws/devel/setup.bash" >> ~/.pibotrc 
114 
115 #alias
116 echo "alias pibot_bringup='roslaunch pibot_bringup bringup.launch'" >> ~/.pibotrc 
117 echo "alias pibot_bringup_with_imu='roslaunch pibot_bringup bringup_with_imu.launch'" >> ~/.pibotrc 
118 echo "alias pibot_lidar='roslaunch pibot_bringup ${PIBOT_LIDAR}.launch'" >> ~/.pibotrc 
119 echo "alias pibot_base='roslaunch pibot_bringup robot.launch'" >> ~/.pibotrc 
120 echo "alias pibot_base_with_imu='roslaunch pibot_bringup robot_with_imu.launch'" >> ~/.pibotrc 
121 echo "alias pibot_control='roslaunch pibot keyboard_teleop.launch'" >> ~/.pibotrc 
122 
123 echo "alias pibot_gmapping='roslaunch pibot_navigation gmapping.launch'" >> ~/.pibotrc 
124 echo "alias pibot_gmapping_with_imu='roslaunch pibot_navigation gammaping_with_imu.launch'" >> ~/.pibotrc 
125 echo "alias pibot_save_map='roslaunch pibot_navigation save_map.launch'" >> ~/.pibotrc 
126 
127 echo "alias pibot_naviagtion='roslaunch pibot_navigation nav.launch'" >> ~/.pibotrc 
128 echo "alias pibot_naviagtion_with_imu='roslaunch pibot_navigation nav_with_imu.launch'" >> ~/.pibotrc 
129 echo "alias pibot_view='roslaunch pibot_navigation view_nav.launch'" >> ~/.pibotrc 
130 
131 echo "alias pibot_cartographer='roslaunch pibot_navigation cartographer.launch'" >> ~/.pibotrc 
132 echo "alias pibot_view_cartographer='roslaunch pibot_navigation view_cartographer.launch'" >> ~/.pibotrc 
133 
134 echo "alias pibot_hector_mapping='roslaunch pibot_navigation hector_mapping.launch'" >> ~/.pibotrc 
135 echo "alias pibot_hector_mapping_without_imu='roslaunch pibot_navigation hector_mapping_without_odom.launch'" >> ~/.pibotrc 
136 
137 echo "alias pibot_karto_slam='roslaunch pibot_navigation karto_slam.launch'" >> ~/.pibotrc 

 

其他出现类似报错的可以参考上面的代码直接把环境变量加到~/.bashrc里面。

 

 

上一篇:苹果或将为iPhone 13全系配备LiDAR


下一篇:传感器标定系列 lidar -- imu