您的位置:首页 > 其它

ROS 学习系列 -- iRobot 第二代机座 Roomba 作为Turtlebot使用时无法开关机

2015-07-05 17:30 537 查看
iRobot 推出了第二代机座 Roomba来取代Create. 这是一个绿脸的机座。

如果使用在turtlebot上,几乎是完全兼容的,不用该什么代码,但是波特率提高了一倍,所以需要更改环境变量。但是在停止所以turtlebot的进程后,发现Roomba不再有任何反应,灯灭了,按任何按钮都不管用,也无法充电,但是电池一直在放电。原因是退出进程时没有进入到passive模式。在full模式和safe模式下,它就是这个反应。

1. 启动turtlebot

apt-get install turtlebot之后,执行下面的脚本来设置Roomba为机座:

export TURTLEBOT_BASE=roomba
export TURTLEBOT_STACKS=circles
export TURTLEBOT_3D_SENSOR=asus_xtion_pro
export TURTLEBOT_SIMULATION=false
export TURTLEBOT_SERIAL_PORT=/dev/ttyUSB0
export ROS_IP=192.168.1.16


按下 Roomba中间的最大按钮 “CLEAN”, 执行下面的脚本启动turtlebot

$ roslaunch turtlebot_bringup minimal.launch


此时发现,连接Roomba的USB口开始持续狂闪,一直不停。但是“CLEAN”按钮的灯灭了。这时按CTRL+C终止,发现USB灯灭了,但是“CLEAN”按钮没有恢复亮灯。无论怎么操作都不管用,Roomba成了废铁。

2. 修改代码

下载了turtlebot的代码后,打开代码文件 src/turtlebot_create/create_node/nodes/turtlebot_node.py, 增加一下几行代码。为 class TurtlebotNode 添加一个函数:

def stop(self):
self.robot.passive()


在 turtlebot_main 函数中添加最后一行 c.stop()

def turtlebot_main(argv):
c = TurtlebotNode()
while not rospy.is_shutdown():
try:
# This sleep throttles reconnecting of the driver.  It
# appears that pyserial does not properly release the file
# descriptor for the USB port in the event that the Create is
# unplugged from the laptop.  This file desecriptor prevents
# the create from reassociating with the same USB port when it
# is plugged back in.  The solution, for now, is to quickly
# exit the driver and let roslaunch respawn the driver until
# reconnection occurs.  However, it order to not do bad things
# to the Create bootloader, and also to keep relaunching at a
# minimum, we have a 3-second sleep.
time.sleep(3.0)

c.start()
c.spin()

except Exception as ex:
msg = "Failed to contact device with error: [%s]. Please check that the Create is powered on and that the connector is plugged into the Create."%(ex)
c._diagnostics.node_status(msg,"error")
rospy.logerr(msg)

finally:
# Driver no longer connected, delete flag from disk
try:
os.remove(connected_file())
except Exception: pass

c.stop()


再次启动turtlebot,然后关闭。Roomba就还可以正常使用了。

版权声明:本文为博主原创文章,未经博主允许不得转载。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: