def signal_lost(): receive_mode="NO_SIGNAL" for chan in range(0,NUM_PWM): cellpilot_usart.set_pwm(chan,0)
#!/usr/bin/python # Copyright (c) 2015 Netforce Co. Ltd. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE # OR OTHER DEALINGS IN THE SOFTWARE. import sys import cellpilot_usart chan=int(sys.argv[1]) dur=int(sys.argv[2]) cellpilot_usart.set_pwm(chan,dur)
else: delay=None if delay<0 or delay>1000: raise Exception("Invalid delay") if len(args)>3: next_pwm=int(args[3]) if next_pwm<0 or next_pwm>2000: raise Exception("Invalid next PWM value") else: next_pwm=None if delay and next_pwm is None: raise Exception("Missing next PWM value") for chan,pwm,delay,next_pwm in actions: if chan in delay_pwms: continue cellpilot_usart.set_pwm(chan,pwm) if delay: delay_pwms[chan]=(val,t+delay,next_pwm) if last_cmd_t and t-last_cmd_t>NO_SIGNAL_DELAY and receive_mode!="NO_SIGNAL": signal_lost() dels=[] for chan,(pwm,sched_t,next_pwm) in delay_pwms.items(): if t>=sched_t: cellpilot_usart.set_pwm(chan,next_pwm) dels.append(chan) for chan in dels: del delay_pwms[chan] next_t=(t+20)*0.001 t1=time.time() sleep_t=next_t-t1 if sleep_t>0:
#!/usr/bin/python # Copyright (c) 2015 Netforce Co. Ltd. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE # OR OTHER DEALINGS IN THE SOFTWARE. import sys import cellpilot_usart chan = int(sys.argv[1]) dur = int(sys.argv[2]) cellpilot_usart.set_pwm(chan, dur)