def main(): for i in range(len(sys.argv)): if sys.argv[i] == '-t': if len(sys.argv) < i + 3: print 'device and baud needed for option -t' exit(1) test(sys.argv[i + 1], int(sys.argv[i + 2])) print 'Servo Server' server = SignalKServer() from sensors import Sensors sensors = Sensors(server) servo = Servo(server, sensors) servo.max_current.set(10) period = .1 start = lastt = time.time() while True: servo.poll() sensors.poll() if servo.controller.value != 'none': print 'voltage:', servo.voltage.value, 'current', servo.current.value, 'ctrl temp', servo.controller_temp.value, 'motor temp', servo.motor_temp.value, 'rudder pos', sensors.rudder.angle.value, 'flags', servo.flags.strvalue( ) #print servo.command.value, servo.speed.value, servo.windup pass server.HandleRequests() dt = period - time.time() + lastt if dt > 0 and dt < period: time.sleep(dt) lastt += period else: lastt = time.time()
def connect(self): watchlist = [ 'ap.enabled', 'ap.mode', 'ap.pilot', 'ap.bell_server', 'ap.heading', 'ap.heading_command', 'gps.source', 'wind.source', 'servo.controller', 'servo.flags', 'ap.pilot.basic.P', 'ap.pilot.basic.I', 'ap.pilot.basic.D' ] self.last_msg = {} host = '' if len(sys.argv) > 1: host = sys.argv[1] def on_con(client): self.value_list = client.list_values(10) for name in watchlist: client.watch(name) try: self.client = SignalKClient(on_con, host) if self.value_list: print('connected') else: client.disconnect() raise 1 except Exception as e: print(e) self.client = False time.sleep(1) self.server = SignalKServer() def Register(_type, name, *args, **kwargs): return self.server.Register(_type(*([name] + list(args)), **kwargs)) ap_bell_server = Register( EnumProperty, 'ap.bell_server', '10.10.10.1', ['10.10.10.1', '10.10.10.2', '10.10.10.4', '192.168.178.129'], persistent=True) self.last_msg['ap.bell_server'] = ap_bell_server.value ap_pilot = Register(StringValue, 'ap.pilot', 'none') self.last_msg['ap.pilot'] = ap_pilot.value
print 'loading servo calibration', filename file = open(filename) self.calibration.set(json.loads(file.readline())) except: print 'WARNING: using default servo calibration!!' self.calibration.set({'forward': [.2, .6], 'reverse': [.2, .6]}) def save_calibration(self): file = open(Servo.calibration_filename, 'w') file.write(json.dumps(self.calibration)) if __name__ == '__main__': import serialprobe print 'Servo Server' server = SignalKServer() serial_probe = serialprobe.SerialProbe() servo = Servo(server, serial_probe) servo.max_current.set(10) period = .1 lastt = time.time() while True: servo.poll() if servo.driver: print 'voltage:', servo.voltage.value, 'current', servo.current.value, 'ctrl temp', servo.controller_temp.value, 'motor temp', servo.motor_temp.value, 'rudder pos', servo.rudder_pos.value, 'flags', servo.flags.strvalue() #print servo.command.value, servo.speed.value, servo.windup pass server.HandleRequests()