max_off_track_count = 1 # off track count max_trick_count = 1 # tolerant tricked count my_pismart = PiSmart() tts = TTS() stt = STT('command', dictionary_update=False) led = LED() lf = line_follower_module.Line_Follower(references=REFERENCES) my_pismart.motor_switch(1) my_pismart.speaker_switch(1) left_motor = Motor('MotorB', forward=0) right_motor = Motor('MotorA', forward=1) left_motor.stop() right_motor.stop() my_pismart.power_type = '2S' my_pismart.speaker_volume = 3 my_pismart.capture_volume = 100 def setup(): tts.say = "Hello, I can track black lines now, Do I need a calibration for the black and white colors?" led.brightness = 60 while True: # 亮灯,开始接收指令。听到指令是yes和no时,分别给calibrate赋值True和False stt.recognize() if stt.result == 'yes': calibrate = True
# i = i + 1 global time time = rospy.Time.now() r = rospy.Rate(100) while not rospy.is_shutdown(): if (rospy.Time.now() - time).to_sec() > 0.5: motorA.speed = 0 motorB.speed = 0 r.sleep() if __name__ == '__main__': try: nodeName = 'pismart0' print nodeName rospy.init_node(nodeName, anonymous=False) rospy.Subscriber(nodeName+'_motor_speed', Vector3, motorCallback) rospy.Subscriber(nodeName+'_led', Int32, ledCallback) print "start listening" t = threading.Thread(target=imuThread) t.start() listener() t.join() except KeyboardInterrupt: motorA.speed = 0 motorB.speed = 0 motorA.stop() motorB.stop() p.motor_switch(0)