Esempio n. 1
0
def SenseHatData(conf, dataobj):
    sense = SenseHat()
    sense.clear()
    zero_pressure = sense.get_pressure()
    while not conf.shutdown:
        # Adjust ground pressure in case of anomaly
        if conf.state == "HALT":
            zero_pressure = zero_pressure * .9 + sense.get_pressure() * .1

        # Altimeter
        data = dataobj.current_data
        current_pressure = sense.get_pressure()
        data["sensors"]["alt"] = get_altitude(
            zero_pressure, sense.get_pressure(),
            sense.get_temperature())  # meters
        data["sensors"]["hum"] = sense.get_humidity()  # %
        data["sensors"]["temp"] = (sense.get_temperature() * 9 / 5) + 32  # F
        data["sensors"]["pres"] = current_pressure
        conf.data.add_dp(current_pressure - conf.data.last_pressure)
        conf.data.last_pressure = current_pressure

        # IMU
        data["sensors"]["acc"] = sense.get_accelerometer_raw()  # Gs
        data["sensors"]["pitch"] = sense.get_accelerometer()[
            "pitch"]  # degrees
        data["sensors"]["yaw"] = sense.get_accelerometer()["yaw"]  # degrees
        data["sensors"]["roll"] = sense.get_accelerometer()["roll"]  # degrees
        data["sensors"]["compass"] = sense.get_compass()  # rad/sec
        data["sensors"]["gyro"] = sense.get_gyroscope_raw()  # rad/sec
        data["sensors"]["mag"] = sense.get_compass_raw()  # microteslas
def gyro():
    sense = SenseHat()
    globals.pitch, globals.roll, globals.yaw = sense.get_accelerometer(
    ).values()
    globals.x, globals.y, globals.z = sense.get_accelerometer_raw().values()
    globals.pitch = round(globals.pitch, 0)
    globals.roll = round(globals.roll, 0)
    globals.yaw = round(globals.yaw, 0)
Esempio n. 3
0
 def _init_(self):
         device_sensor = SenseHat()
         self.device_id = 4
         self.device_lon = random.uniform(-76.8, -77.2)
         self.device_lat = random.uniform(38.75, 39.0)
         self.device_last_time = time.time()
         self.device_last_temp = device_sensor.get_gyroscope()
         self.device_last_humidity = device_sensor.get_accelerometer()
         self.device_last_mag = device_sensor.get_compass()
         self.device_last_pressure = device_sensor.get_pressure()
         return self
Esempio n. 4
0
def main():
    from sense_hat import SenseHat
    sense = SenseHat()
    sense.clear()
    sense.low_light = True
    sense.set_imu_config(True, True, True)
    sensor_start = sense.get_accelerometer()
    sensor_sensitivity = .0001
    move_list = []
    ex_coll = get_db('zs5_mongo', 'sensor')['freezer']
    while True:
        sensor_in = sense.get_accelerometer()
        move_size = (sensor_in['roll'] - sensor_start['roll'])**2 + (
            sensor_in['pitch'] - sensor_start['pitch'])**2 + (
                sensor_in['yaw'] - sensor_start['yaw'])**2
        sensor_start = sensor_in
        if move_size >= sensor_sensitivity:
            sense.show_letter('M')
            move_dict = {'move_ts': datetime.utcnow().timestamp(), **sensor_in}
            ex_coll.insert_one(move_dict)
        time.sleep(.2)
        sense.clear()
Esempio n. 5
0
def root():
    sense = SenseHat()
    temp1 = sense.get_temperature()
    temp2 = sense.get_temperature_from_pressure()
    pressure = sense.get_pressure()
    north = sense.get_compass()
    accel_only = sense.get_accelerometer()
    acc_raw = sense.get_accelerometer_raw()
    temp = "Temp {:10.4f}".format(temp1) + " {:10.4f}".format(temp2)
    other = "Pres {:10.4f}".format(pressure) + " Compas {:10.4f}".format(north)
    acc1 = "p: {pitch}, r: {roll}, y: {yaw}".format(**accel_only)
    acc2 = "x: {x}, y: {x}, z: {z}".format(**acc_raw)
    print temp + "\n" + other + "\n" + acc1 + "\n" + acc2 + "\n"
Esempio n. 6
0
def root():
    sense = SenseHat()
    temp1 = sense.get_temperature()   
    temp2 = sense.get_temperature_from_pressure() 
    pressure = sense.get_pressure()
    north = sense.get_compass()
    accel_only = sense.get_accelerometer()
    acc_raw = sense.get_accelerometer_raw()
    temp = "Temp {:10.4f}".format(temp1) + " {:10.4f}".format(temp2) 
    other = "Pres {:10.4f}".format(pressure) + " Compas {:10.4f}".format(north)
    acc1 = "p: {pitch}, r: {roll}, y: {yaw}".format(**accel_only)
    acc2 = "x: {x}, y: {x}, z: {z}".format(**acc_raw)
    print temp + "\n" + other + "\n" + acc1 + "\n" + acc2 + "\n"
Esempio n. 7
0
class IMU:
    def __init__(self):
        self.sense = SenseHat()
        self.sense.clear()
        self.zero_pressure = self.sense.get_pressure()

    def get_accelerometer():
        return self.sense.get_accelerometer()

    def get_compass():
        return self.sense.get_compass()

    def get_accerometer_raw():
        return self.sense.get_accelerometer_raw()

    def get_gyroscope_raw():
        return self.sense.get_gyroscope_raw()

    def get_compass_raw():
        return self.sense.get_compass_raw()
Esempio n. 8
0
 def update_accel(self):
         device_sensor = SenseHat()
         self.device_last_temp = device_sensor.get_accelerometer()
         self.device_last_time = time.time()
Esempio n. 9
0
class SenseHATPlugin(EPLPluginBase):
    def __init__(self, init):
        super(SenseHATPlugin, self).__init__(init)
        self.getLogger().info("SenseHATPlugin initialised with config: %s" %
                              self.getConfig())
        self.sense = SenseHat()

    @EPLAction("action<integer >")
    def setRotation(self, angle=None):
        """
		Orientation of the message/image 
		
		@param message:	Orientation of the message, The supported values of orientation are 0, 90, 180, and 270..
		"""
        if angle == None: angle = 90

        self.sense.set_rotation(angle)

    @EPLAction("action<integer, integer, integer, integer, integer >")
    def setPixel(self, x, y, r, g, b):
        self.sense.set_pixel(x, y, r, g, b)

    @EPLAction("action< sequence <sequence <integer> > >")
    def setPixels(self, pixels):
        if not isinstance(pixels, list): return
        self.sense.set_pixels(pixels)

    @EPLAction("action< >")
    def clear(self):
        self.sense.clear()

    @EPLAction("action< integer, integer, integer >")
    def Clear(self, r, g, b):
        self.sense.clear(r, g, b)

    @EPLAction("action<string >")
    def showMessage(self, message):
        self.sense.show_message(message)

    @EPLAction("action<string, float, sequence<integer>, sequence<integer> >")
    def displayMessage(self,
                       message,
                       scrollingSpeed=None,
                       textColor=None,
                       backgroundColor=None):
        """
		This method will scrolls a text message across the LED Matrix.
				
		@param message:	The Scrolling message to be displayed.
		@param scrollingSpeed:	Scrolling message speed.
		@param textColor:	 The text color of the scrolling message i.e [R G B] .
		@param backgroundColor:	 The background color of the scrolling message [R G B].
		
		"""
        if scrollingSpeed == None: scrollingSpeed = 0.1
        if (textColor == None) or (not isinstance(textColor, list)):
            textColor = [255, 255, 255]
        if (backgroundColor
                == None) or (not isinstance(backgroundColor, list)):
            backgroundColor = [0, 0, 0]

        self.sense.show_message(message,
                                scroll_speed=scrollingSpeed,
                                text_colour=textColor,
                                back_colour=backgroundColor)

    @EPLAction("action<string >")
    def showLetter(self, letter):
        if not isinstance(letter, basestring): return
        self.sense.show_letter(letter)

    @EPLAction("action<boolean >")
    def lowLight(self, islowLight):
        self.sense.low_light = islowLight

    @EPLAction("action<string >")
    def loadImage(self, imagePath):
        self.sense.load_image(imagePath)

    ##########################################################################################################

    #				Environmental sensors

    ##########################################################################################################

    @EPLAction("action<> returns float")
    def getHumidity(self):
        humidity = self.sense.get_humidity()
        return round(humidity, 2)

    @EPLAction("action<> returns float")
    def getTemperature(self):
        temp = self.sense.get_temperature()
        return round(temp, 2)

    @EPLAction("action<> returns float")
    def getTemperatureFromHumidity(self):
        temp = self.sense.get_temperature_from_humidity()
        return round(temp, 2)

    @EPLAction("action<> returns float")
    def getTemperatureFromPressure(self):
        temp = self.sense.get_temperature_from_pressure()
        return round(temp, 2)

    @EPLAction("action<> returns float")
    def getPressure(self):
        pressure = self.sense.get_pressure()
        return round(pressure, 2)

    ##########################################################################################################

    #				Joystick

    ##########################################################################################################

    @EPLAction("action<boolean > returns com.apamax.sensehat.InputEvent")
    def waitForEvent(self, emptyBuffer=False):
        jevent = self.sense.stick.wait_for_event(emptybuffer=emptyBuffer)
        evtInstance = Event(
            'com.apamax.sensehat.InputEvent', {
                "actionValue": jevent.action,
                "directionValue": jevent.direction,
                "timestamp": jevent.timestamp
            })
        return evtInstance

    @EPLAction("action<> returns sequence<com.apamax.sensehat.InputEvent >")
    def getEvents(self):

        events = list()
        for event in self.sense.stick.get_events():
            evtInstance = Event(
                'com.apamax.sensehat.InputEvent', {
                    "actionValue": jevent.action,
                    "directionValue": jevent.direction,
                    "timestamp": jevent.timestamp
                })
            events.append(evtInstance)

        return events

    def pushed_up(event):
        if event.action == ACTION_RELEASED:
            joyevt = Event('com.apamax.sensehat.JoystickControl',
                           {"controlType": 1})
            Correlator.sendTo("sensedhat_data", joyevt)

    def pushed_down(event):
        if event.action == ACTION_RELEASED:
            joyevt = Event('com.apamax.sensehat.JoystickControl',
                           {"controlType": 2})
            Correlator.sendTo("sensedhat_data", joyevt)

    def pushed_left(event):
        if event.action == ACTION_RELEASED:
            joyevt = Event('com.apamax.sensehat.JoystickControl',
                           {"controlType": 3})
            Correlator.sendTo("sensedhat_data", joyevt)

    def pushed_right(event):
        if event.action == ACTION_RELEASED:
            joyevt = Event('com.apamax.sensehat.JoystickControl',
                           {"controlType": 4})
            Correlator.sendTo("sensedhat_data", joyevt)

    def pushed_in(event):
        if event.action == ACTION_RELEASED:
            self.sense.show_message(str(round(sense.temp, 1)), 0.05, b)

    ##########################################################################################################

    #				IMU Sensor

    ##########################################################################################################

    @EPLAction("action<boolean, boolean, boolean >")
    def setIMUConfig(self, compassEnabled, gyroscopeEnabled,
                     accelerometerEnabled):
        '''
     	Enables and disables the gyroscope, accelerometer and/or magnetometer contribution to the get orientation functions
     
     	@param compassEnabled :        enable compass
     	@param gyroscopeEnabled :      enable gyroscope
      	@param accelerometerEnabled :  enable accelerometer
      	
     	'''
        self.sense.set_imu_config(compassEnabled, gyroscopeEnabled,
                                  accelerometerEnabled)

    @EPLAction("action< > returns com.apamax.sensehat.IMUData")
    def getOrientationRadians(self):
        '''		
     	Gets the current orientation in radians using the aircraft principal axes of pitch, roll and yaw
     
     	@return event with pitch, roll and yaw values. Values are floats representing the angle of the axis in radians
     
		'''

        pitch, roll, yaw = self.sense.get_orientation_radians().values()
        evtInstance = Event('com.apamax.sensehat.IMUData', {
            "pitch": pitch,
            "roll": roll,
            "yaw": yaw
        })
        return evtInstance

    @EPLAction("action< > returns com.apamax.sensehat.IMUData")
    def getOrientationDegrees(self):
        '''		
     	Gets the current orientation in degrees using the aircraft principal axes of pitch, roll and yaw
     
     	@return event with pitch, roll and yaw values. Values are Floats representing the angle of the axis in degrees
     
		'''

        pitch, roll, yaw = self.sense.get_orientation_degrees().values()
        evtInstance = Event('com.apamax.sensehat.IMUData', {
            "pitch": pitch,
            "roll": roll,
            "yaw": yaw
        })
        return evtInstance

    @EPLAction("action< > returns com.apamax.sensehat.IMUData")
    def getOrientation(self):
        '''
     	@return event with pitch, roll and yaw representing the angle of the axis in degrees
     
		'''

        pitch, roll, yaw = self.sense.get_orientation().values()
        evtInstance = Event('com.apamax.sensehat.IMUData', {
            "pitch": pitch,
            "roll": roll,
            "yaw": yaw
        })
        return evtInstance

    @EPLAction("action< > returns float")
    def getCompass(self):
        '''
		Calls set_imu_config internally in Python core to disable the gyroscope and accelerometer
     	then gets the direction of North from the magnetometer in degrees
     
     	@return The direction of North
     	
		'''
        return self.sense.get_compass()

    @EPLAction("action< > returns com.apamax.sensehat.IMUDataRaw")
    def getCompassRaw(self):
        '''
		
     	Gets the raw x, y and z axis magnetometer data     
     	@return event representing the magnetic intensity of the axis in microteslas (uT)
     
     	'''
        x, y, z = self.sense.get_compass_raw().values()
        evtInstance = Event('com.apamax.sensehat.IMUDataRaw', {
            "x": x,
            "y": y,
            "z": z
        })
        return evtInstance

    @EPLAction("action< > returns com.apamax.sensehat.IMUData")
    def getGyroscope(self):
        '''
		Calls set_imu_config internally in Python core to disable the magnetometer and accelerometer
     	then gets the current orientation from the gyroscope only
     	
     	@return event with pitch, roll and yaw representing the angle of the axis in degrees
     
		'''

        pitch, roll, yaw = self.sense.get_gyroscope().values()
        evtInstance = Event('com.apamax.sensehat.IMUData', {
            "pitch": pitch,
            "roll": roll,
            "yaw": yaw
        })
        return evtInstance

    @EPLAction("action< > returns com.apamax.sensehat.IMUDataRaw")
    def getGyroscopeRaw(self):
        '''		
     	Gets the raw x, y and z axis gyroscope data     
     	@return event representing the rotational intensity of the axis in radians per second
     
     	'''
        x, y, z = sense.get_gyroscope_raw().values()
        evtInstance = Event('com.apamax.sensehat.IMUDataRaw', {
            "x": x,
            "y": y,
            "z": z
        })
        return evtInstance

    @EPLAction("action< > returns com.apamax.sensehat.IMUData")
    def getAccelerometer(self):
        '''
		Calls set_imu_config in Python core to disable the magnetometer and gyroscope
        then gets the current orientation from the accelerometer only
     
        @return Object representing the angle of the axis in degrees
             
		'''

        pitch, roll, yaw = self.sense.get_accelerometer().values()
        evtInstance = Event('com.apamax.sensehat.IMUData', {
            "pitch": pitch,
            "roll": roll,
            "yaw": yaw
        })
        return evtInstance

    @EPLAction("action< > returns com.apamax.sensehat.IMUDataRaw")
    def getAccelerometerRaw(self):
        '''		
     	Gets the raw x, y and z axis accelerometer data    
     	@return event representing the acceleration intensity of the axis in Gs
     
     	'''
        x, y, z = sense.get_accelerometer_raw().values()
        evtInstance = Event('com.apamax.sensehat.IMUDataRaw', {
            "x": x,
            "y": y,
            "z": z
        })
        return evtInstance
Esempio n. 10
0
        timestamp = datetime.now().strftime("%d/%m/%Y-%H:%M:%S:%f")

        #calculate position of iss
        iss.compute()
        lat = str(iss.sublat).split(':')
        long = str(iss.sublong).split(':')

        #get pitch, roll and yaw orientation from gyro
        o = sense.get_orientation()
        gyro_pitch = o['pitch']
        gyro_roll = o['roll']
        gyro_yaw = o['yaw']

        #get acceleration
        acc_x, acc_y, acc_z = sense.get_accelerometer_raw().values()
        acc_roll, acc_pitch, acc_yaw = sense.get_accelerometer().values()

        #get magnetometer values
        mag_x, mag_y, mag_z = sense.get_compass_raw().values()
        compass = sense.get_compass()

        #get gyro velocity
        gyro_vel = sense.get_gyroscope_raw()
        gyro_vel_x = gyro_vel['x']
        gyro_vel_y = gyro_vel['y']
        gyro_vel_z = gyro_vel['z']

        #get humidity
        humidity = sense.get_humidity()

        #get temperature
Esempio n. 11
0
sense = SenseHat()
t = sense.get_temperature()
p = sense.get_pressure()
h = sense.get_humidity()

t = round(t, 3)
p = round(p, 3)
h = round(h, 3)

msg = "Temp is %s, Pres is %s, Humidity is %s" % (t, p, h)
print(msg)
#sense.show_message(msg,scroll_speed = 0.05)

#x,y,z = sense.get_accelerometer_raw().values()
x, y, z = sense.get_accelerometer().values()

x = round(x, 3)
y = round(y, 3)
z = round(z, 3)

msg = "X is %s, Y is %s, Z is %s" % (x, y, z)
print(msg)
#sense.show_message(msg,scroll_speed = 0.05)

#gyro_x,gyro_y,gyro_z = sense.get_gyroscope_raw().values()
gyro_x, gyro_y, gyro_z = sense.get_gyroscope().values()

msg = "Gyro X is %s, Gyro Y is %s, Gyro Z is %s" % (gyro_x, gyro_y, gyro_z)
print(msg)
Esempio n. 12
0
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            sense.set_pixel(5, y, 0, 0, 0)
            if event.key == K_DOWN and y < 5:
                y += 2
            elif event.key == K_UP and y > 1:
                y -= 2
            sense.set_pixel(5, y, 255, 255, 255)
            if event.key == K_RETURN and y == 1:
                toleranz = 0.5
            if event.key == K_RETURN and y == 3:
                toleranz = 0.3
            if event.key == K_RETURN and y == 5:
                toleranz = 0.1



accel_only = sense.get_accelerometer()
print("p: {pitch}, r: {roll}, y: {yaw}".format(**accel_only))


print(accel_only["pitch"])

#LR = math.tan(x)) * 100
#OU = math.tan(y) * 100


#print({pitch})

#print type ()
Esempio n. 13
0
while True:
    #Dessin de base:
    sense.set_pixel(1, 7, 0, 255, 0)
    sense.set_pixel(2, 7, 0, 255, 0)
    sense.set_pixel(4, 7, 0, 255, 0)
    sense.set_pixel(5, 7, 0, 255, 0)
    sense.set_pixel(1, 6, 0, 255, 0)
    sense.set_pixel(2, 6, 0, 255, 0)
    sense.set_pixel(4, 6, 0, 255, 0)
    sense.set_pixel(5, 6, 0, 255, 0)
    sense.set_pixel(3, 5, 0, 255, 0)
    sense.set_pixel(3, 6, 0, 255, 0)
    sense.set_pixel(3, 4, 0, 255, 0)

    #On recupere des capteurs en tous genre
    accel_only = sense.get_accelerometer()
    roll = round(accel_only["roll"], 1)
    pitch = round(accel_only["pitch"], 1)
    yaw = round(accel_only["yaw"], 1)

    temp = sense.get_temperature()

    mqttc.publish("sensor/temperature", payload=temp, qos=0, retain=False)
    mqttc.publish("sensor/accelero/roll", payload=roll, qos=0, retain=False)
    mqttc.publish("sensor/accelero/pitch", payload=pitch, qos=0, retain=False)
    mqttc.publish("sensor/accelero/yaw", payload=yaw, qos=0, retain=False)

    time.sleep(1)
    sense.clear()
    print(roll)
Esempio n. 14
0
sh.set_pixels(locked_screen)

### unlock function ###


def unlock():
    """unlocking function"""

    sh.set_pixels(unlocked_screen)
    sleep(2)
    sh.show_message("You have unlocked it!!")


### locks ###

while True:
    if round(sh.get_humidity()) >= 50:
        unlocked1 = True

    if unlocked1 == True and round(int(sh.get_compass())):
        unlocked2 = True

    if unlocked2 == True and round(sh.get_temperature()) >= 26:
        unlocked3 = True

    if unlocked3 == True and round(int(sh.get_accelerometer()['roll'])) >= 57:
        unlocked4 = True
        unlock()
        quit()
Esempio n. 15
0
    print("pitch = {}, roll  = {}, yell = {}".format(
        round(orientation["pitch"], 2), round(orientation["roll"], 2),
        round(orientation["yaw"], 2)))

    #gyro_only = sense.get_gyroscope()#仅从陀螺仪获取当前方向
    #print("p: {pitch}, r: {roll}, y: {yaw}".format(**gyro_only))
    #print(sense.gyro)
    #print(sense.gyroscope)

    #raw = sense.get_gyroscope_raw()#获取原始的x,y和z轴陀螺仪数据
    #print("x: {x}, y: {y}, z: {z}".format(**raw))
    #print(sense.gyro_raw)
    #print(sense.gyroscope_raw)

    sense.set_imu_config(False, False, True)  #只启用加速度计
    accel_only = sense.get_accelerometer()  #禁用磁力计和陀螺仪,然后仅从加速度计获取当前方向
    print("pitch = {pitch}, roll = {roll}, yaw = {yaw}".format(**accel_only))
    #print(sense.accel)
    #print(sense.accelerometer)

    acceleration = sense.get_accelerometer_raw()  #获取原始的x,y和z轴加速度计数据
    x = round(acceleration['x'], 3)
    y = round(acceleration['y'], 3)
    z = round(acceleration['z'], 3)
    print("x = {}, y = {}, z = {}".format(x, y, z))

    for i in range(64):
        a = random.randint(1, 8)
        D.append(color[a - 1])
    sense.set_pixels(D)
    D = []
Esempio n. 16
0
sense = SenseHat()

sense.clear((0, 255, 0))
sense.low_light = True

GAIN = 2

client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#client_socket.settimeout(1.0)
addr = ("X.X.X.X", 12001)

values = [0]*4

while True:
    # start = time.time()
    # Read all the ADC channel values in a list.
    for i in range(4):
        values[i] = (adc.read_adc(i, gain=GAIN))
   
    gyro = dict.values(sense.get_gyroscope())
    accelero = dict.values(sense.get_accelerometer())
    compass = (sense.get_compass())
    # end = time.time()
    message = "%i %i %i %i %.2f %.2f %.2f %.2f %.2f %.2f %.2f" %(values[0], values[1], values[2], values[3], gyro[0], accelero[0], gyro[1], accelero[1], gyro[2], accelero[2], compass)
    client_socket.sendto(message, addr)
    
    # print(end - start)

    #time.sleep(0.5)
	
        
Esempio n. 17
0
### sensor
print( sensehat.gamma )
print( "Humidity : %.4f %%rH" %	sensehat.get_humidity( ) )
print( "Temp main: %.4f C" %	sensehat.get_temperature( ) )
print( "Temp humd: %.4f C" %	sensehat.get_temperature_from_humidity( ) )
print( "Temp prss: %.4f C" %	sensehat.get_temperature_from_pressure( ) )
print( "Pressure : %.4f mb" %	sensehat.get_pressure( ) ) # millibar

sensehat.set_imu_config( True , True , True )

print( "p: {pitch} , r: {roll} , y: {yaw}".format( **sensehat.get_orientation_radians( ) ) )
print( "p: {pitch} , r: {roll} , y: {yaw}".format( **sensehat.get_orientation_degrees( ) ) )
print( "p: {pitch} , r: {roll} , y: {yaw}".format( **sensehat.get_orientation( ) ) )
print( "p: {pitch} , r: {roll} , y: {yaw}".format( **sensehat.get_gyroscope( ) ) )
print( "p: {pitch} , r: {roll} , y: {yaw}".format( **sensehat.get_accelerometer( ) ) )
print( "North: %s" % sensehat.get_compass( ) )

print( sensehat.get_compass_raw( ) )
print( "x: {x} , y: {y} , z: {z}".format( **sensehat.get_compass_raw( ) ) )

print( "x: %.4f" % sensehat.get_compass_raw( )['x']
  + " , y: %.4f" % sensehat.get_compass_raw( )['y']
  + " , Z: %.4f" % sensehat.get_compass_raw( )['z'] )
print( "x: %.4f" % sensehat.get_gyroscope_raw( )['x']
  + " , y: %.4f" % sensehat.get_gyroscope_raw( )['y']
  + " , Z: %.4f" % sensehat.get_gyroscope_raw( )['z'] )
print( "x: %.4f" % sensehat.get_accelerometer_raw( )['x']
  + " , y: %.4f" % sensehat.get_accelerometer_raw( )['y']
  + " , Z: %.4f" % sensehat.get_accelerometer_raw( )['z'] )
Esempio n. 18
0
from sense_hat import SenseHat

sense = SenseHat()
sense.set_imu_config(True, True, True)

# Python SenseHat API documentation:
# https://pythonhosted.org/sense-hat/api

# Roll is: angular x.
# Pitch is: angular y.
# Yaw is: angular z.

data_imu = {}
data_imu["gyro"] = sense.get_orientation_degrees(
)  # Gets orientation (3-ang-axis) in [deg].
data_imu["acc"] = sense.get_accelerometer(
)  # Gets orientation from the accelerometer (3-ang-axis) in [deg].
data_imu["gyror"] = sense.get_gyroscope_raw(
)  # Gets angular velocity (3-axis) in [rad/s].
data_imu["mag"] = sense.get_compass()  # Gets orientation to North in [deg].
data_imu["magr"] = sense.get_compass_raw(
)  # Gets magnetic field (3-axis) in [µT].
data_imu["accr"] = sense.get_accelerometer_raw(
)  # Gets acceleration (3-axis) in [g]'s.

data_env = {}
data_env["temph"] = sense.get_temperature_from_humidity(
)  # Gets temperature from humidity sensor in [ºC].
data_env["tempp"] = sense.get_temperature_from_pressure(
)  # Gets temperature from pressure sensor in [ºC].
data_env["pres"] = sense.get_pressure()  # Gets pressure in [mbar].
data_env["hum"] = sense.get_humidity()  # Gets relative humidity in [%].
Esempio n. 19
0
prev_x = 0
prev_y = 0

led_degree_ratio = len(led_loop) / 360.0

sense.set_rotation(0)
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)

while True:
    sense.show_message("Hi!  I'm ScubaPi", text_colour=red)
    dir = sense.get_compass()
    mytemp = sense.get_temperature()
    myhumid = sense.get_humidity()
    myacc = sense.get_accelerometer()
#    print "Direction  " + str(round(dir,1)) + " Temp " +str(round(mytemp,1)) + " Humidity " + str(round(myhumid,1))
#    print "Pitch " + str(round(myacc['pitch'],1)) + " Yaw " + str(round(myacc['yaw'],1)) + " Roll " + str(round(myacc['roll'],1))
    sense.show_message( "Direction  " + str(round(dir,1)) + " Temp " +str(round(mytemp,1)) + " Humidity " + str(round(myhumid,1)), text_colour=green)
    sense.show_message("Pitch " + str(round(myacc['pitch'],1)) + " Yaw " + str(round(myacc['yaw'],1)) + " Roll " + str(round(myacc['roll'],1)), text_colour=blue)
#    dir_inverted = 360 - dir  # So LED appears to follow North
#    led_index = int(led_degree_ratio * dir_inverted)
#    offset = led_loop[led_index]

#    y = offset // 8  # row
#    x = offset % 8  # column

#    if x != prev_x or y != prev_y:
#        sense.set_pixel(prev_x, prev_y, 0, 0, 0)

#    sense.set_pixel(x, y, 0, 0, 255)
Esempio n. 20
0
    orientation = fedora.get_orientation()
    orientation_pitch = orientation.get('pitch')
    orientation_roll = orientation.get('roll')
    orientation_yaw = orientation.get('yaw')

    #get compass
    compass = fedora.get_compass()

    #get gyroscope
    gyro = fedora.get_gyroscope()
    gyro_pitch = gyro.get('pitch')
    gyro_roll = gyro.get('roll')
    gyro_yaw = gyro.get('yaw')

    #get accelerometer
    accelerometer = fedora.get_accelerometer()
    accelerometer_pitch = accelerometer.get('pitch')
    accelerometer_roll = accelerometer.get('roll')
    accelerometer_yaw = accelerometer.get('yaw')

    #write to csv
    with open("atmosphere.csv", 'a') as atm:
        data_writer = csv.DictWriter(atm, fieldnames=fields)
        data_writer.writerow({
            'humidity': humidity,
            'temp': temp,
            'temp_from_humidity': temp_from_humidity,
            'temp_from_pressure': temp_from_pressure,
            'pressure': pressure,
            'orientation_pitch': orientation_pitch,
            'orientation_roll': orientation_roll,
Esempio n. 21
0
    def start(self):
        self.enable = True

        self.imuPub = rospy.Publisher(self.robot_host + '/imu',
                                      Imu,
                                      queue_size=10)
        self.imuRawPub = rospy.Publisher(self.robot_host + '/imu/raw',
                                         Imu,
                                         queue_size=10)

        self.accelerometerPub = rospy.Publisher(self.robot_host +
                                                '/imu/accelerometer',
                                                Accelerometer,
                                                queue_size=10)
        self.accelerometerPitchPub = rospy.Publisher(
            self.robot_host + '/imu/accelerometer/pitch', Pitch, queue_size=10)
        self.accelerometerRollPub = rospy.Publisher(self.robot_host +
                                                    '/imu/accelerometer/roll',
                                                    Roll,
                                                    queue_size=10)
        self.accelerometerYawPub = rospy.Publisher(self.robot_host +
                                                   '/imu/accelerometer/yaw',
                                                   Yaw,
                                                   queue_size=10)
        self.accelerometerRawPub = rospy.Publisher(self.robot_host +
                                                   '/imu/accelerometer/raw',
                                                   Accelerometer,
                                                   queue_size=10)
        self.accelerometerRawXPub = rospy.Publisher(self.robot_host +
                                                    '/imu/accelerometer/raw/x',
                                                    Float64,
                                                    queue_size=10)
        self.accelerometerRawYPub = rospy.Publisher(self.robot_host +
                                                    '/imu/accelerometer/raw/y',
                                                    Float64,
                                                    queue_size=10)
        self.accelerometerRawZPub = rospy.Publisher(self.robot_host +
                                                    '/imu/accelerometer/raw/z',
                                                    Float64,
                                                    queue_size=10)

        self.gyroscopePub = rospy.Publisher(self.robot_host + '/imu/gyroscope',
                                            Gyroscope,
                                            queue_size=10)
        self.gyroscopePitchPub = rospy.Publisher(self.robot_host +
                                                 '/imu/gyroscope/pitch',
                                                 Pitch,
                                                 queue_size=10)
        self.gyroscopeRollPub = rospy.Publisher(self.robot_host +
                                                '/imu/gyroscope/roll',
                                                Roll,
                                                queue_size=10)
        self.gyroscopeYawPub = rospy.Publisher(self.robot_host +
                                               '/imu/gyroscope/yaw',
                                               Yaw,
                                               queue_size=10)
        self.gyroscopeRawPub = rospy.Publisher(self.robot_host +
                                               '/imu/gyroscope/raw',
                                               Gyroscope,
                                               queue_size=10)
        self.gyroscopeRawXPub = rospy.Publisher(self.robot_host +
                                                '/imu/gyroscope/raw/x',
                                                Float64,
                                                queue_size=10)
        self.gyroscopeRawYPub = rospy.Publisher(self.robot_host +
                                                '/imu/gyroscope/raw/y',
                                                Float64,
                                                queue_size=10)
        self.gyroscopeRawZPub = rospy.Publisher(self.robot_host +
                                                '/imu/gyroscope/raw/z',
                                                Float64,
                                                queue_size=10)

        self.magnetometerPub = rospy.Publisher(self.robot_host +
                                               '/imu/magnetometer',
                                               Magnetometer,
                                               queue_size=10)
        self.magnetometerRawPub = rospy.Publisher(self.robot_host +
                                                  '/imu/magnetometer/raw',
                                                  Orientation,
                                                  queue_size=10)

        self.orientationPub = rospy.Publisher(self.robot_host +
                                              '/imu/orientation',
                                              Orientation,
                                              queue_size=10)
        self.orientationDegreePub = rospy.Publisher(self.robot_host +
                                                    '/imu/orientation/degrees',
                                                    Orientation,
                                                    queue_size=10)
        self.orientationRadiansPub = rospy.Publisher(
            self.robot_host + '/imu/orientation/radians',
            Orientation,
            queue_size=10)
        self.orientationNorthPub = rospy.Publisher(self.robot_host +
                                                   '/imu/orientation/north',
                                                   Magnetometer,
                                                   queue_size=10)

        sense = SenseHat()

        while not rospy.is_shutdown():
            accel_only = sense.get_accelerometer()
            accel_raw = sense.get_accelerometer_raw()

            gyro_only = sense.get_gyroscope()
            gyro_raw = sense.get_gyroscope_raw()

            north = sense.get_compass()
            compass = sense.get_compass_raw()

            orientation = sense.get_orientation()
            orientation_deg = sense.get_orientation_degrees()
            orientation_rad = sense.get_orientation_radians()

            imu_msg = Imu()
            imu_msg.header.stamp = rospy.Time.now()
            imu_msg.header.frame_id = "/base_link"
            imu_msg.linear_acceleration.x = accel_only['pitch']
            imu_msg.linear_acceleration.y = accel_only['roll']
            imu_msg.linear_acceleration.z = accel_only['yaw']
            imu_msg.angular_velocity.x = gyro_only['pitch']
            imu_msg.angular_velocity.y = gyro_only['roll']
            imu_msg.angular_velocity.z = gyro_only['yaw']
            imu_msg.orientation.x = orientation['pitch']
            imu_msg.orientation.y = orientation['roll']
            imu_msg.orientation.z = orientation['yaw']
            imu_msg.orientation.w = 0
            imu_msg.orientation_covariance = [
                99999.9, 0.0, 0.0, 0.0, 99999.9, 0.0, 0.0, 0.0, 99999.9
            ]
            imu_msg.angular_velocity_covariance = [
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            ]
            imu_msg.linear_acceleration_covariance = [
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            ]

            imu_raw_msg = Imu()
            imu_raw_msg.header.stamp = rospy.Time.now()
            imu_raw_msg.header.frame_id = "/base_link"
            imu_raw_msg.linear_acceleration.x = accel_raw['x']
            imu_raw_msg.linear_acceleration.y = accel_raw['y']
            imu_raw_msg.linear_acceleration.z = accel_raw['z']
            imu_raw_msg.angular_velocity.x = gyro_raw['x']
            imu_raw_msg.angular_velocity.y = gyro_raw['y']
            imu_raw_msg.angular_velocity.z = gyro_raw['z']
            imu_raw_msg.orientation.x = compass['x']
            imu_raw_msg.orientation.y = compass['y']
            imu_raw_msg.orientation.z = compass['z']
            imu_raw_msg.orientation.w = north
            imu_raw_msg.orientation_covariance = [
                99999.9, 0.0, 0.0, 0.0, 99999.9, 0.0, 0.0, 0.0, 99999.9
            ]
            imu_raw_msg.angular_velocity_covariance = [
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            ]
            imu_raw_msg.linear_acceleration_covariance = [
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            ]

            accel_msg = Accelerometer()
            accel_msg.header.stamp = rospy.Time.now()
            accel_msg.header.frame_id = "/base_link"
            accel_msg.x = accel_only['pitch']
            accel_msg.y = accel_only['roll']
            accel_msg.z = accel_only['yaw']

            accel_pitch_msg = Pitch()
            accel_pitch_msg.header.stamp = rospy.Time.now()
            accel_pitch_msg.header.frame_id = "/base_link"
            accel_pitch_msg.data = accel_only['pitch']

            accel_roll_msg = Roll()
            accel_roll_msg.header.stamp = rospy.Time.now()
            accel_roll_msg.header.frame_id = "/base_link"
            accel_roll_msg.data = accel_only['roll']

            accel_yaw_msg = Yaw()
            accel_yaw_msg.header.stamp = rospy.Time.now()
            accel_yaw_msg.header.frame_id = "/base_link"
            accel_yaw_msg.data = accel_only['yaw']

            accel_raw_msg = Accelerometer()
            accel_raw_msg.header.stamp = rospy.Time.now()
            accel_raw_msg.header.frame_id = "/base_link"
            accel_raw_msg.x = accel_raw['x']
            accel_raw_msg.y = accel_raw['y']
            accel_raw_msg.z = accel_raw['z']

            accel_raw_x_msg = Float64()
            accel_raw_x_msg.header.stamp = rospy.Time.now()
            accel_raw_x_msg.header.frame_id = "/base_link"
            accel_raw_x_msg.data = accel_raw['x']

            accel_raw_y_msg = Float64()
            accel_raw_y_msg.header.stamp = rospy.Time.now()
            accel_raw_y_msg.header.frame_id = "/base_link"
            accel_raw_y_msg.data = accel_raw['y']

            accel_raw_z_msg = Float64()
            accel_raw_z_msg.header.stamp = rospy.Time.now()
            accel_raw_z_msg.header.frame_id = "/base_link"
            accel_raw_z_msg.data = accel_raw['z']

            gyro_msg = Gyroscope()
            gyro_msg.header.stamp = rospy.Time.now()
            gyro_msg.header.frame_id = "/base_link"
            gyro_msg.x = gyro_only['pitch']
            gyro_msg.y = gyro_only['roll']
            gyro_msg.z = gyro_only['yaw']

            gyro_pitch_msg = Pitch()
            gyro_pitch_msg.header.stamp = rospy.Time.now()
            gyro_pitch_msg.header.frame_id = "/base_link"
            gyro_pitch_msg.data = gyro_only['pitch']

            gyro_roll_msg = Roll()
            gyro_roll_msg.header.stamp = rospy.Time.now()
            gyro_roll_msg.header.frame_id = "/base_link"
            gyro_roll_msg.data = gyro_only['roll']

            gyro_yaw_msg = Yaw()
            gyro_yaw_msg.header.stamp = rospy.Time.now()
            gyro_yaw_msg.header.frame_id = "/base_link"
            gyro_yaw_msg.data = gyro_only['yaw']

            gyro_raw_msg = Gyroscope()
            gyro_raw_msg.header.stamp = rospy.Time.now()
            gyro_raw_msg.header.frame_id = "/base_link"
            gyro_raw_msg.x = gyro_raw['x']
            gyro_raw_msg.y = gyro_raw['y']
            gyro_raw_msg.z = gyro_raw['z']

            gyro_raw_x_msg = Float64()
            gyro_raw_x_msg.header.stamp = rospy.Time.now()
            gyro_raw_x_msg.header.frame_id = "/base_link"
            gyro_raw_x_msg.data = gyro_raw['x']

            gyro_raw_y_msg = Float64()
            gyro_raw_y_msg.header.stamp = rospy.Time.now()
            gyro_raw_y_msg.header.frame_id = "/base_link"
            gyro_raw_y_msg.data = gyro_raw['y']

            gyro_raw_z_msg = Float64()
            gyro_raw_z_msg.header.stamp = rospy.Time.now()
            gyro_raw_z_msg.header.frame_id = "/base_link"
            gyro_raw_z_msg.data = gyro_raw['z']

            north_msg = Magnetometer()
            north_msg.header.stamp = rospy.Time.now()
            north_msg.header.frame_id = "/base_link"
            north_msg.north = north

            compass_msg = Orientation()
            compass_msg.header.stamp = rospy.Time.now()
            compass_msg.header.stamp = rospy.Time.now()
            compass_msg.x = compass['x']
            compass_msg.y = compass['y']
            compass_msg.z = compass['z']

            orientation_msg = Orientation()
            orientation_msg.header.stamp = rospy.Time.now()
            orientation_msg.header.stamp = rospy.Time.now()
            orientation_msg.x = orientation['pitch']
            orientation_msg.y = orientation['roll']
            orientation_msg.z = orientation['yaw']

            orientation_degree_msg = Orientation()
            orientation_degree_msg.header.stamp = rospy.Time.now()
            orientation_degree_msg.header.stamp = rospy.Time.now()
            orientation_degree_msg.x = orientation_deg['pitch']
            orientation_degree_msg.y = orientation_deg['roll']
            orientation_degree_msg.z = orientation_deg['yaw']

            orientation_rad_msg = Orientation()
            orientation_rad_msg.header.stamp = rospy.Time.now()
            orientation_rad_msg.header.stamp = rospy.Time.now()
            orientation_rad_msg.x = orientation_rad['pitch']
            orientation_rad_msg.y = orientation_rad['roll']
            orientation_rad_msg.z = orientation_rad['yaw']

            rospy.loginfo(
                "imu/accelerometer: p: {pitch}, r: {roll}, y: {yaw}".format(
                    **accel_only))
            rospy.loginfo(
                "imu/accelerometer/raw: x: {x}, y: {y}, z: {z}".format(
                    **accel_raw))
            rospy.loginfo(
                "imu/gyroscope: p: {pitch}, r: {roll}, y: {yaw}".format(
                    **gyro_only))
            rospy.loginfo(
                "imu/gyroscope/raw: x: {x}, y: {y}, z: {z}".format(**gyro_raw))
            rospy.loginfo("imu/magnetometer: North: %s" % north)
            rospy.loginfo(
                "imu/magnetometer/raw: x: {x}, y: {y}, z: {z}".format(
                    **compass))
            rospy.loginfo(
                "imu/orientation: p: {pitch}, r: {roll}, y: {yaw}".format(
                    **orientation))
            rospy.loginfo(
                "imu/orientation/degrees: p: {pitch}, r: {roll}, y: {yaw}".
                format(**orientation_deg))
            rospy.loginfo(
                "imu/orientation/radians: p: {pitch}, r: {roll}, y: {yaw}".
                format(**orientation_rad))
            rospy.loginfo("imu/orientation/north: North: %s" % north)

            self.imuPub.publish(imu_msg)
            self.imuRawPub.publish(imu_raw_msg)

            self.accelerometerPub.publish(accel_msg)
            self.accelerometerPitchPub.publish(accel_pitch_msg)
            self.accelerometerRollPub.publish(accel_roll_msg)
            self.accelerometerYawPub.publish(accel_yaw_msg)
            self.accelerometerRawPub.publish(accel_raw_msg)
            self.accelerometerRawXPub.publish(accel_raw_x_msg)
            self.accelerometerRawYPub.publish(accel_raw_y_msg)
            self.accelerometerRawZPub.publish(accel_raw_z_msg)

            self.gyroscopePub.publish(gyro_msg)
            self.gyroscopePitchPub.publish(gyro_pitch_msg)
            self.gyroscopeRollPub.publish(gyro_roll_msg)
            self.gyroscopeYawPub.publish(gyro_yaw_msg)
            self.gyroscopeRawPub.publish(gyro_raw_msg)
            self.gyroscopeRawXPub.publish(gyro_raw_x_msg)
            self.gyroscopeRawYPub.publish(gyro_raw_y_msg)
            self.gyroscopeRawZPub.publish(gyro_raw_z_msg)

            self.magnetometerPub.publish(north_msg)
            self.magnetometerRawPub.publish(compass_msg)

            self.orientationPub.publish(orientation_msg)
            self.orientationDegreePub.publish(orientation_degree_msg)
            self.orientationRadiansPub.publish(orientation_rad_msg)
            self.orientationNorthPub.publish(north_msg)

            self.rate.sleep()
Esempio n. 22
0
deviceShadowHandler.shadowRegisterDeltaCallback(customShadowCallback_Delta)
deviceShadowHandler.shadowGet(customShadowCallback_Get, 5)

myMQTTClient = myAWSIoTMQTTShadowClient.getMQTTConnection()
# Infinite offline Publish queueing
myMQTTClient.configureOfflinePublishQueueing(-1)
myMQTTClient.configureDrainingFrequency(2)  # Draining: 2 Hz
myMQTTClient.configureConnectDisconnectTimeout(10)  # 10 sec
myMQTTClient.configureMQTTOperationTimeout(5)  # 5 sec
# Loop forever and wait for joystic
# Use the sensehat module

time.sleep(2)
while True:
    temp = sense.get_temperature()
    humidity = sense.get_humidity()
    accel = sense.get_accelerometer()
    payload = {
        'Temperature': temp,
        'Humidity': humidity,
        'Accelerometer': {
            'Pitch': accel['pitch'],
            'Roll': accel['roll'],
            'Yaw': accel['yaw']
        }
    }
    print(topic)
    print(json.dumps(payload))
    myMQTTClient.publish(topic, json.dumps(payload), 1)
    time.sleep(2)
Esempio n. 23
0
vs = VideoStream(usePiCamera=not simulation_mode).start()
time.sleep(1.0)

cv2.namedWindow("ROV", cv2.WINDOW_NORMAL)
cv2.resizeWindow('ROV', 600, 600)
pygame.init()

auto = False
use_keyboard = True
use_controller = False

telemetry_dict = {'light': 'OFF'}

if auto:
    yaw_abs = sense.get_accelerometer()['yaw']
    press_abs = sense.get_pressure()
dict_sensors = 0

direction = ''

while True:
    telemetry_dict['direction'] = direction
    frame = vs.read()
    dict_sensors = f.get_dict_sensors(sense, telemetry_dict)
    f.display_telemetry(frame, dict_sensors)
    cv2.imshow("ROV", frame)
    direction = ''
    key = cv2.waitKey(1) & 0xFF
    if auto:
        if 0 < gyro['yaw'] < 180: