def set_pwm_ch3(mavfile): #set_servo doesn't work in mavproxy. Toggle servos doesn't work in Mission Planer either #master.set_servo(args.servo_channel, args.pwm) #Overriding RC command (works in MAVProxy) unused = 0xFFFF #rc_channels_override_send(target_system, target_component, chan_i_raw) unused channels have UInt16_max while not command.end_entered(): pwm_ch3 = raw_input('PWM value (range:1000-2000, safety and test purposes limited 1400-1600) for channel 3 or end/0 : ') if pwm_ch3 == 'end': set_motor_pwm(mavfile, 1500) print('Module override motor ended. Releasing the channel') release_channel(mavfile) break try: pwm_ch3 = int(pwm_ch3) except: print('couldnt handle input') pass if pwm_ch3 >= 1000 and pwm_ch3 <= 2000 and isinstance(pwm_ch3, int): set_motor_pwm(mavfile, pwm_ch3) elif pwm_ch3 == 0: #First 2 parameters are target_system, target_component, last 8 are to release override #mavfile.mav.rc_channels_override_send(0,0,0,0,0,0,0,0,0,0) set_motor_pwm(mavfile, 1500) print('Motor in idle mode: PWM 1500') pass else: print('PWM has to be integer between 1400 and 1550')
def set_pwm_ch4(mavfile): #set_servo doesn't work in mavproxy. Toggle servos doesn't work in Mission Planer either #master.set_servo(args.servo_channel, args.pwm) #Overriding RC command (works in MAVProxy) unused = 0xFFFF #rc_channels_override_send(target_system, target_component, chan_i_raw) unused channels have UInt16_max while not command.end_entered(): pwm_ch4 = raw_input('PWM value for channel 4 or end : ') #pwm_ch4 = int(pwm_ch4) #mavfile.mav.rc_channels_override_send(mavfile.target_system,mavfile.target_component,unused,unused,unused,pwm_ch4,unused,unused,unused,unused) if pwm_ch4 == 'end': set_servo_pwm(mavfile, 1500) time.sleep(1) print('Releasing channel. Ending now') release_channel(mavfile) break try: pwm_ch4 = int(pwm_ch4) except: print('couldnt handle input') pass if pwm_ch4 >= 1000 and pwm_ch4 <= 20000 and isinstance(pwm_ch4, int): print("OK") #print(mavfile.target_system) #print(mavfile.target_component) #mavfile.mav.rc_channels_override_send(1,1,unused,unused,unused,pwm_ch4,unused,unused,unused,unused) #mavfile.mav.rc_channels_override_send(mavfile.target_system,mavfile.target_component,unused,unused,unused,pwm_ch4,unused,unused,unused,unused) set_servo_pwm(mavfile, pwm_ch4) else: print('PWM has to be integer between 1000 and 2000')
def autopilot(mavfile): print('Starting') while not command.end_entered(): mode = raw_input('Which mode: (idle, circle, line) ') t_sleep = int(raw_input('Autopilot time: ')) if mode == 'end': break elif mode == 'circle': print('Driving a circle') print('Moving servo') set_servo(mavfile, 2000) sleep(1) print('Starting motor') set_motor(mavfile,1530) sleep(t_sleep) print('Turning off motor') set_motor(mavfile, convert_speed(v = 0)) sleep(1) print('idle') set_servo(mavfile, 1500) release_channel(mavfile) print('done') elif mode == 'line': print('Forward starting') set_motor(mavfile, 1530) sleep(t_sleep) print('Stopping for 2 seconds') set_motor(mavfile, convert_speed(v = 0)) sleep(2) print('Backward starting') set_motor(mavfile, 1470) sleep(t_sleep) print('idle') set_motor(mavfile, convert_speed(v = 0)) release_channel(mavfile) elif mode == 'idle': print('doing nothing') else: print('Mode not supported (yet)')