53 from serial.serialutil
import SerialException, SerialTimeoutException
59 SaneSubSys = [
'motors']
61 -------------------------------------------------------------------------------" 68 def __init__(self, kwargs):
73 for subsys
in self.
kwargs[
'subsys']:
74 if subsys ==
'motors':
78 def runMotorControllersSanity(self):
81 'front': {
'addr': SysConf.MotorCtlrAddrFront},
82 'rear': {
'addr': SysConf.MotorCtlrAddrRear}
94 motorctlr = RoboClaw.RoboClaw()
97 device = SysConf.MotorCtlrDevName
98 baud = SysConf.MotorCtlrBaudRate
100 print "Opening motor controller serial interface %s@%d" % (device, baud)
102 motorctlr.open(device, baud)
103 except RoboClaw.RoboClawException
as inst:
104 print 'Error:', inst.message
109 if motorctlr.isOpen():
110 for k, d
in ctlrInfo.iteritems():
115 Gpio.enableMotorCtlrsPower(
False)
119 def saneMotorCtlr(self, motorctlr, key, addr):
122 print "*** Restore Laelaps %s motor controller sanity ***" % (key)
132 Kp = 500 * RoboClaw.ParamVelPidCvt
133 Ki = 100 * RoboClaw.ParamVelPidCvt
134 Kd = 5 * RoboClaw.ParamVelPidCvt
138 maxAmps= 4.5 / RoboClaw.ParamAmpScale
141 motorctlr.setMainBatterySettings(addr, 60, 340)
142 except RoboClaw.RoboClawException
as inst:
143 print "Failed to set main battery cutoffs.", inst.message
146 motorctlr.setLogicBatterySettings(addr, 55, 340)
147 except RoboClaw.RoboClawException
as inst:
148 print "Failed to set logic battery cutoffs.", inst.message
151 motorctlr.setM1EncoderMode(addr, 0)
152 except RoboClaw.RoboClawException
as inst:
153 print "Failed to set motor 1 encoder mode to quadrature.", inst.message
156 motorctlr.setM2EncoderMode(addr, 0)
157 except RoboClaw.RoboClawException
as inst:
158 print "Failed to set motor 2 encoder mode to quadrature.", inst.message
161 motorctlr.setM1Pidq(addr, Kp, Ki, Kd, Qpps)
162 except RoboClaw.RoboClawException
as inst:
163 print "Failed to set motor 1 velocity PID.", inst.message
166 motorctlr.setM2Pidq(addr, Kp, Ki, Kd, Qpps)
167 except RoboClaw.RoboClawException
as inst:
168 print "Failed to set motor 2 velocity PID:", inst.message
171 motorctlr.setM1MaxCurrentLimit(addr, maxAmps)
172 except RoboClaw.RoboClawException
as inst:
173 print "Failed to set motor 1 maximum current.", inst.message
176 motorctlr.setM2MaxCurrentLimit(addr, maxAmps)
177 except RoboClaw.RoboClawException
as inst:
178 print "Failed to set motor 2 maximum current.", inst.message
223 self.
_Argv0 = os.path.basename(__file__)
233 print "%s: Error: %s" % (self.
_Argv0, emsg)
235 print "%s: Error" % (self.
_Argv0)
236 print "Try '%s --help' for more information." % (self.
_Argv0)
242 usage: %s [OPTIONS] SUBSYS [SUBSYS ...] 247 Options and arguments: 248 -h, --help : Display this help and exit. 250 SUBSYS : Laelaps subsystem. One of: motors 251 motors - Motors and motor controllers 254 On success, 0. An exit status of 128 indicates usage 271 self.
_Argv0 = os.path.basename(kwargs.get(
'argv0', __file__))
274 kwargs[
'debug'] =
False 275 kwargs[
'subsys'] = []
279 opts, args = getopt.getopt(argv[1:],
"?h",
281 except getopt.error, msg:
283 for opt, optarg
in opts:
284 if opt
in (
'-h',
'--help',
'-?'):
293 if subsys
in SaneSubSys:
294 kwargs[
'subsys'] += [subsys]
296 self.
printUsageErr(
"%s: Unknown/unsupported subsystem." % (subsys))
309 def run(self, argv=None, **kwargs):
331 if __name__ ==
'__main__':
333 sys.exit( app.run() );
def run(self, argv=None, kwargs)
Run application.
def __init__(self)
Constructor.
Laelaps diagnositcs application class.
def printUsage(self)
Print Command-Line Usage Message.
Unit test command-line exception class.
def runMotorControllersSanity(self)
msg
error message attribute
def __init__(self, msg)
Constructor.
def saneMotorCtlr(self, motorctlr, key, addr)
def getOptions(self, argv=None, kwargs)
Get command-line options.
def printUsageErr(self, emsg)
Print usage error.