def run(self): rospy.init_node('adeept_car_driver') rate = rospy.Rate(10) while not rospy.is_shutdown(): self._publish_sonar() rate.sleep() motor.destroy()
def destroy(): #motor stops when this program exit motor.destroy() GPIO.cleanup()
target=led_thread) #Define a thread for ws_2812 leds led_threading.setDaemon( True ) #'True' means it is a front thread,it would close when the mainloop() closes led_threading.start() #Thread starts tasks = [ remote_control.read_gamepad_input(), remote_control.rumble(), read_gamepad_inputs() ] loop.run_until_complete( asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)) led.red() loop.run_until_complete(removetasks(loop)) motor.destroy() disconnect_sound.play(1.0) except Exception as e: print("Error occured " + str(e)) finally: if remote_control != None: remote_control.power_on = False #remote_control.erase_rumble() if (strip != None): led_strip.colorWipe(strip, Color(0, 0, 0)) print("Closing async loop..") loop.run_until_complete(loop.shutdown_asyncgens()) loop.close() led.both_off()
def stopWhenObstacle(): m.motorStart(1, m.Dir_forward, 80) while 1: if u.checkdist() < dist: m.motorStop() break def turnLeftWhenObstacle(): m.motorStart(1, m.Dir_forward, 90) while 1: if u.checkdist() < dist: #m.motorStop() t.left() #m.motorStart(1, m.Dir_forward, 100) while u.checkdist() < dist: pass t.middle() while 1: if u.checkdist() < dist: m.motorStop() break try: turnLeftWhenObstacle() except KeyboardInterrupt: m.destroy()
def destroy(): motor.destroy() GPIO.cleanup()
elif exact != False: return (t2-t1)*340/2 # gives the answers in meters def ultra_tester(severity=0.5): #just controlling distance with the ultrasonic dist = checkdist(exact=True) if dist < (severity - 0.1): move.move_backward(60) elif dist > (severity + 0.1): move.move_forward(60) elif dist >= (severity - 0.1) and dist <= (severity + 0.1): move.motorStop() if __name__ == '__main__': ap = argparse.ArgumentParser(description = "True for with motor, false for without motor") ap.add_argument("with_motor", nargs='?', default=False, type=bool, help ="Do you want to test with the motor or not") args = ap.parse_args() move.setup() try: if args.with_motor == True: move.setup() while True: ultra_tester(severity=0.3) else: while True: print(checkdist(exact=True)) except: move.destroy()