Hello again!
I keep stumbling into this problem:
unexpected indent line 38.
This is the code I’m trying:
#!/usr/bin/env python
'''
Example Module
Peter barker, September 2016
This module simply serves as a starting point for your own MAVProxy module.
1. copy this module sidewise (e.g. "cp mavproxy_example.py mavproxy_coolfeature.py"
2. replace all instances of "example" with whatever your module should be called
(e.g. "coolfeature")
3. trim (or comment) out any functionality you do not need
'''
import time, os
from MAVProxy.modules.lib import mp_module
from pymavlink import mavutil
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
arming_masks = {
"all" : 0x0001,
"baro" : 0x0002,
"compass" : 0x0004,
"gps" : 0x0008,
"ins" : 0x0010,
"params" : 0x0020,
"rc" : 0x0040,
"voltage" : 0x0080,
"battery" : 0x0100
}
class RpiModule(mp_module.MPModule):
def __init__(self, mpstate):
super(RpiModule, self).__init__(mpstate, "rpi", "arm/disarm handling")
self.add_command('arm', self.cmd_arm2, 'arm motors')
self.add_command('disarm', self.cmd_disarm, 'disarm motors')
self.was_armed = False
def switch_18(channel):
self.cmd_arm2()
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(18, GPIO.RISING, callback=switch_18, bouncetime=200)
def cmd_arm2(self, args):
self.master.arducopter_arm()
while True:
pass
def cmd_disarm(self, args):
'''disarm motors'''
p2 = 0
if len(args) == 1 and args[0] == 'force':
p2 = 21196
self.master.mav.command_long_send(
self.target_system, # target_system
0,
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, # command
0, # confirmation
0, # param1 (0 to indicate disarm)
p2, # param2 (all other params meaningless)
0, # param3
0, # param4
0, # param5
0, # param6
0) # param7
def mavlink_packet(self, m):
mtype = m.get_type()
if mtype == 'HEARTBEAT' and m.type != mavutil.mavlink.MAV_TYPE_GCS:
armed = self.master.motors_armed()
if armed != self.was_armed:
self.was_armed = armed
if armed and not self.all_checks_enabled():
self.say("Arming checks disabled")
def init(mpstate):
'''initialise module'''
return RpiModule(mpstate)
Any suggestions on what I’m doing wrong?
Alex