Skip to content

Commit

Permalink
Update car.py
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-dvorak authored Dec 1, 2023
1 parent 12bf6ad commit 78f76a6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions car/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
print("GPS ERROR")
sys.exit()

proc=subprocess.Popen(["./mavlink-routerd", "-c", "TF-GCS.conf"])
time.sleep(5)
qgcproc=subprocess.Popen(["./QGroundControl.AppImage"])
#proc=subprocess.Popen(["./mavlink-routerd", "-c", "TF-GCS.conf"])
#time.sleep(5)
#subprocess.Popen(["./QGroundControl.AppImage"])

connection = mavutil.mavlink_connection('tcp:127.0.0.1:5760',source_system=1,source_component=139)
#connection = mavutil.mavlink_connection('tcp:127.0.0.1:5760',source_system=1,source_component=139)
connection = mavutil.mavlink_connection('udpin:127.0.0.1:14445',source_system=1,source_component=139)
connection.mav.heartbeat_send(mavutil.mavlink.MAV_TYPE_ONBOARD_CONTROLLER,
mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0)

Expand Down Expand Up @@ -73,8 +74,9 @@
msg = connection.recv_match(blocking=True,timeout=5)
if msg:
#update data and send to server
print("MSG:",msg.get_type())
print("MSG:", msg.get_type(), msg)
if msg.get_type() in messages:
k = msg.get_type()
members=vars(msg)
changetime=str(datetime.datetime.utcnow())
for m in messages[msg.get_type()]:
Expand All @@ -83,10 +85,13 @@
sended=False

if msg.get_type()=="GPS_RAW_INT":
#print(msg)
#print(type(msg))
#print(msg.lat)
state["lastPosUpdate"]=str(datetime.datetime.utcnow())
state["latitude"]=float(msg["lat"])/10000000.0
state["longitude"]=float(msg["lat"])/10000000.0
state["altitude"]=float(msg["alt"])/1000.0
state["latitude"]=float(msg.lat)/10000000.0
state["longitude"]=float(msg.lon)/10000000.0
state["altitude"]=float(msg.alt)/1000.0
print(state["lastPosUpdate"]," ",state["latitude"]," ",state["longitude"]," ",state["altitude"])
sended=False

Expand All @@ -111,6 +116,7 @@
#try send
try:
print("Sending Data to CDP")
print(state)
response = requests.post(f"{cdpAddres}{dataEndPoint}", json=state)
print(response)

Expand All @@ -120,7 +126,3 @@

except Exception as e:
print("Error couldnt send Data to CDP",e)




0 comments on commit 78f76a6

Please sign in to comment.