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就還可以正常使用了。
版權聲明:本文爲博主原創文章,未經博主允許不得轉載。