00001 #!/usr/bin/env python 00002 import rospy 00003 import struct 00004 import sys 00005 from std_msgs.msg import String 00006 from wheeled_robin_driver import WheeledRobin 00007 #from create_driver import SerialCommandInterface 00008 00009 def printf(format, *args): 00010 sys.stdout.write(format % args) 00011 00012 def talker(): 00013 pub = rospy.Publisher('chatter', String) 00014 rospy.init_node('talker') 00015 00016 robot = WheeledRobin() 00017 #serial = SerialCommandInterface('/dev/ttyUSB0', 38400) 00018 00019 robot.start() 00020 #rospy.sleep(2.5) 00021 #robot.sci.start() 00022 robot.control() 00023 rospy.sleep(0.5) 00024 00025 #robot.sci.control_params(180,18,110,50,50,30) 00026 #rospy.sleep(1.0) 00027 #robot.control() 00028 #robot.drive(130,0) 00029 #rospy.sleep(3.0) 00030 #robot.drive(0,0) 00031 #rospy.sleep(5.0) 00032 #robot.drive(-130,0) 00033 #rospy.sleep(3.0) 00034 #robot.drive(0,0) 00035 #rospy.sleep(1.0) 00036 #robot.sci.start() 00037 #r = rospy.Rate(100) 00038 #while not rospy.is_shutdown(): 00039 #rospy.loginfo("Driving with -200 mm/s") 00040 #robot.drive(0,1000) 00041 #rospy.sleep(1.0) 00042 #robot.drive(0,0) 00043 #rospy.sleep(1.0) 00044 #robot.drive(0,-1000) 00045 #rospy.sleep(1.0) 00046 #robot.drive(0,0) 00047 #rospy.loginfo(" ") 00048 #robot.sci.sensors(1) 00049 #a = robot.sci.ser.read(17) 00050 #robot.sci.flush_input() 00051 #rospy.sleep(0.5) 00052 #robot.sci.sensors(22) 00053 #b = robot.sci.ser.read(1) 00054 # PacketID:0 00055 #(e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16) = struct.unpack('>8h1B5h2B',a) 00056 #printf('res: %r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r, %r\n',e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15,e16) 00057 # PacketID:1 00058 #(e1,e2,e3,e4,e5,e6,e7,e8,e9) = struct.unpack('>8h1B',a) 00059 #printf('res: %r, %r, %r, %r, %r, %r, %r, %r, %r\n',e1,e2,e3,e4,e5,e6,e7,e8,e9) 00060 # PacketID:7-22 00061 #(e2) = struct.unpack('>h',a) 00062 #printf('res: %r\n', e2) 00063 #rospy.loginfo(a) 00064 #r.sleep() 00065 00066 00067 if __name__ == '__main__': 00068 try: 00069 talker() 00070 except rospy.ROSInterruptException: 00071 pass