robot upstart 问题
1.启动后在记录文件发现左轮节点未启动:
因为左边的类未实例化,不会去订阅消息然后初始化
2.两个节点均可以启动后,发现启动后又死掉
因为在程序里有getenv(“HOME”)然后付给string,getenv返回为NULL时程序会报错死掉
3.robot upstart 的用户权限比较低,没有权限操作串口(使用chmod 777 /dev/ttyS*,重启后失效)
通过udev修改权限,具体如下:
在/etc/udev/rules.d/文件夹下添加文件50-chmod-tty.rules,内容如下:
KERNEL=="ttyS[0-9]*", SUBSYSTEM=="tty", GROUP="dialout", MODE="0666"
4.最后发现具备了操作串口的权限,但打开串口失败,修改如下:
int left_wheel_motor::UART0_Open(char *port) { int fdd; fdd = open( port, O_RDWR|O_NOCTTY|O_NDELAY); if (FALSE == fdd) { perror("Can't Open Serial Port"); return(FALSE); } if(fcntl(fdd, F_SETFL, 0) < 0) //if and else: set as block { printf("fcntl failed!\n"); return(FALSE); } else { printf("fcntl=%d\n",fcntl(fdd, F_SETFL,0)); } if(0 == isatty(STDIN_FILENO)) { printf("standard input is not a terminal device\n"); return(FALSE); } else { printf("isatty success!\n"); } printf("fd->open=%d\n",fdd); return fdd; } 改为: int left_wheel_motor::UART0_Open(char *port) { int fdd; fdd = open( port, O_RDWR|O_NOCTTY); if (FALSE == fdd) { perror("Can't Open Serial Port"); return(FALSE); } printf("fd->open=%d\n",fdd); return fdd; }
1、安装包
sudo apt-get install ros-kinetic-robot-upstart
2、install 命令:要启动的launch文件
rosrun robot_upstart install package/launch/xxx.launch
3、启动服务
sudo service package start
4、重启验证
rosnode list或者rostopic list 查看是否启动成功
5、停止服务
sudo service package stop
6、卸载服务,关闭自启动
rosrun robot_upstart uninstall package
7、如果自启动失败可查看log文件(~/.ros, /var/log/syslog, /var/log/upstart)
如果自启动失败可通过下面查看原因(ubuntu18.04需安装sudo apt install setpriv)
pi@NanoPC-T4:~$ sudo systemctl start middleware
pi@NanoPC-T4:~$ sudo systemctl status middleware
pi@NanoPC-T4:~$ sudo systemctl stop middleware
pi@NanoPC-T4:~$ sudo systemctl disable middleware
pi@NanoPC-T4:~$ sudo systemctl enable middleware
pi@NanoPC-T4:~$ sudo systemctl start middleware
其它:export | grep ROS
env | grep ROS