Esempio n. 1
0
    def __init__(self, client, boatimu):
        from rudder import Rudder
        from nmea import Nmea
        from signalk import signalk

        self.client = client

        # services that can receive sensor data
        self.nmea = Nmea(self)
        self.signalk = signalk(self)
        self.gpsd = gpsd(self)

        # actual sensors supported
        self.gps = gps(client)
        self.wind = Wind(client, boatimu)
        self.rudder = Rudder(client)
        self.apb = APB(client)
        self.water = Water(client)

        self.sensors = {
            'gps': self.gps,
            'wind': self.wind,
            'rudder': self.rudder,
            'apb': self.apb,
            'water': self.water
        }
Esempio n. 2
0
class Sensors(object):
    def __init__(self, server):
        from gpsd import gpsd
        from rudder import Rudder
        from nmea import Nmea

        self.server = server
        self.nmea = Nmea(server, self)
        self.gps = gpsd(server, self)
        self.wind = Wind(server)
        self.rudder = Rudder(server)
        self.apb = APB(server)

        self.sensors = {
            'gps': self.gps,
            'wind': self.wind,
            'rudder': self.rudder,
            'apb': self.apb
        }

    def poll(self):
        self.gps.poll()
        self.nmea.poll()
        self.rudder.poll()

        # timeout sources
        t = time.time()
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.source.value == 'none':
                continue
            if t - sensor.lastupdate > 8:
                self.lostsensor(sensor)

    def lostsensor(self, sensor):
        print('sensor', sensor.name, 'lost', sensor.source.value,
              sensor.device)
        sensor.source.set('none')
        sensor.reset()
        sensor.device = None

    def write(self, sensor, data, source):
        if not sensor in self.sensors:
            print('unknown data parsed!', sensor)
            return
        self.sensors[sensor].write(data, source)

    def lostdevice(self, device):
        # optional routine  useful when a device is
        # unplugged to skip the normal data timeout
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.device and sensor.device[2:] == device:
                self.lostsensor(sensor)
Esempio n. 3
0
    def __init__(self, server):
        from gpsd import Gpsd
        from rudder import Rudder
        from nmea import Nmea
        
        self.server = server
        self.nmea = Nmea(server, self)
        self.gps = Gpsd(server, self)
        self.wind = Wind(server)
        self.rudder = Rudder(server)

        self.sensors = {'gps': self.gps, 'wind': self.wind, 'rudder': self.rudder}
Esempio n. 4
0
class Sensors(object):
    def __init__(self, server):
        from gpsd import Gpsd
        from rudder import Rudder
        from nmea import Nmea

        self.server = server
        self.nmea = Nmea(server, self)
        self.gps = Gpsd(server, self)
        self.wind = Wind(server)
        self.rudder = Rudder(server)

        self.sensors = {
            'gps': self.gps,
            'wind': self.wind,
            'rudder': self.rudder
        }

    def poll(self):
        self.gps.poll()
        self.nmea.poll()
        self.rudder.poll()

        # timeout sources
        t = time.time()
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.source.value == 'none':
                continue
            if t - sensor.lastupdate > 8:
                print 'sensor timeout for', name, 'source', sensor.source.value, t - sensor.lastupdate
                sensor.source.set('none')
                sensor.device = None

    def write(self, sensor, data, source):
        if not sensor in self.sensors:
            print 'unknown data parsed!', sensor
            return

        self.sensors[sensor].write(data, source)
class Boat:
    orientation = RigidTransform2d(
        Translation2d(0.0 * unit.meter, 0.0 * unit.meter),
        Rotation2d(1.0, 0.0))

    # Boat relative ([1.0, 0.0] is always 1 m/s forwards)
    velocity = Vector2d(0.0 * unit.meter / unit.second,
                        0.0 * unit.meter / unit.second)
    angularVelocity = 0 * unit.radian / unit.second

    MOI = 10 * unit.kg * unit.meter**2

    fwdCrossSectionArea = 1 * unit.foot * 2 * unit.foot
    sideCrossSectionArea = 8 * unit.foot * 2 * unit.foot

    sail = Sail()
    rudder = Rudder()

    forwardCd = 0.15
    sideCd = 1.2
    viscFriction = 1e1 * unit.newton * unit.meter * unit.second

    def __init__(self):
        pass

    @property
    def spankerAngle(self):
        return self.sail.trailingEdgeAngle

    @spankerAngle.setter
    def spankerAngle(self, newAngle: Rotation2d):
        self.sail.trailingEdgeAngle = newAngle

    @property
    def rudderAngle(self):
        return self.rudder.angle

    @rudderAngle.setter
    def rudderAngle(self, newAngle: Rotation2d):
        self.rudder.angle = newAngle

    def update(self, *, dt):
        forceFromSail = self.sail.update(
            dt=dt,
            boatRelativeWindAngle=Wind.angle.rotateBy(
                self.orientation.rot.rotation))
Esempio n. 6
0
class Sensors(object):
    def __init__(self, client):
        from rudder import Rudder
        from nmea import Nmea
        from signalk import signalk

        self.client = client

        # services that can receive sensor data
        self.nmea = Nmea(self)
        self.signalk = signalk(self)
        self.gpsd = gpsd(self)

        # actual sensors supported
        self.gps = gps(client)
        self.wind = Wind(client)
        self.rudder = Rudder(client)
        self.apb = APB(client)

        self.sensors = {
            'gps': self.gps,
            'wind': self.wind,
            'rudder': self.rudder,
            'apb': self.apb
        }

    def poll(self):
        self.nmea.poll()
        self.signalk.poll()
        self.gpsd.poll()
        self.rudder.poll()

        # timeout sources
        t = time.monotonic()
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.source.value == 'none':
                continue
            if t - sensor.lastupdate > 8:
                self.lostsensor(sensor)

    def lostsensor(self, sensor):
        print('sensor', sensor.name, 'lost', sensor.source.value,
              sensor.device)
        sensor.source.set('none')
        sensor.reset()
        sensor.device = None

    def lostgpsd(self):
        if self.gps.source.value == 'gpsd':
            self.lostsensor(self.gps)

    def write(self, sensor, data, source):
        if not sensor in self.sensors:
            print('unknown data parsed!', sensor)
            return
        self.sensors[sensor].write(data, source)

    def lostdevice(self, device):
        # optional routine  useful when a device is
        # unplugged to skip the normal data timeout
        for name in self.sensors:
            sensor = self.sensors[name]
            if sensor.device and sensor.device[2:] == device:
                self.lostsensor(sensor)