Browse Source

EV3 battery status added

master
Luis Waldhauser 1 year ago
parent
commit
20bad535eb
2 changed files with 18 additions and 18 deletions
  1. 16
    5
      software/roboter/raspy/functions.py
  2. 2
    13
      software/roboter/raspy/raspy_sensors.py

+ 16
- 5
software/roboter/raspy/functions.py View File

@@ -96,23 +96,34 @@ def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
clients.publish(Topics["ROBOT_DATA_POSITION"], json.dumps(position, indent=4))


def get_batteryStatus(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
def get_BatteryStatus(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
"""
Callback function for battery status request
Function to read battery status from ev3 and send via MQTT
8,5V -> 100%
5V -> 0%

Args:
clients (mqtt.Client): current mqtt client
userdata (_type_): _description_
message (mqtt.MQTTMessage): received message
"""
print("Received battery status request")

try:
batteryLevel = int(os.popen('sshpass -p maker ssh robot@ev3dev.local cat /sys/devices/platform/battery/power_supply/lego-ev3-battery/voltage_now').read())
except:
print("Robot not connected")
#TODO Error Message
return

batteryLevel = round(batteryLevel / 1000000, 2) # Voltage
batteryLevel = batteryLevel - 5
batteryLevel = round(batteryLevel / 3.5, 3) *100 # Percentage

battery = {
"Battery": 0.0
"Battery": batteryLevel
}

#TODO read Battery
clients.publish(Topics["ROBOT_DATA_BATTERY"], json.dumps(battery, indent=4))

#endregion

+ 2
- 13
software/roboter/raspy/raspy_sensors.py View File

@@ -16,7 +16,7 @@ class RaspySensors:
"""
Init all Sensors
"""
#[ ]TODO Message if Error
#TODO Message if Error

#Air Temperature & Humidity
@@ -81,18 +81,7 @@ class RaspySensors:
Returns:
_type_: _description_
"""
return self.position
#TODO - read battery from EV3
def readBattery(self):
"""
Read and return battery of ev3

Returns:
_type_: _description_
"""
return self.battery
return self.position


#for Testing only

Loading…
Cancel
Save