Skip to content

Commit

Permalink
positions!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
adenjonah committed May 22, 2024
1 parent 79ca551 commit 674996b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion server/json_databases/DCUUIA.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"timestamp": "2024-05-22T02:37:43.559983", "dcu": {"eva1": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": true, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": true, "eva2_water_waste": false, "oxy_vent": false, "depress": true}}
{"timestamp": "2024-05-22T02:59:43.095802", "dcu": {"eva1": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}, "eva2": {"batt": false, "oxy": false, "comm": false, "fan": false, "pump": false, "co2": false}}, "uia": {"eva1_power": false, "eva1_oxy": false, "eva1_water_supply": false, "eva1_water_waste": true, "eva2_power": false, "eva2_oxy": false, "eva2_water_supply": true, "eva2_water_waste": false, "oxy_vent": false, "depress": true}}
22 changes: 9 additions & 13 deletions server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ async def get_warnings():
def utm_to_latlon(easting, northing, zone_number=15, zone_letter='R'):
return utm.to_latlon(easting, northing, zone_number, zone_letter)

@app.get('/update_positions')
def fetch_and_update_positions():
try:
# URLs for the rover and IMU data
Expand All @@ -173,9 +174,11 @@ def fetch_and_update_positions():

# Fetching data
rover_response = requests.get(rover_url)
rover_response.raise_for_status() # Ensure we raise an error for bad status codes
rover_data = rover_response.json()

imu_response = requests.get(imu_url)
imu_response.raise_for_status() # Ensure we raise an error for bad status codes
imu_data = imu_response.json()

# Getting positions for rover, eva1, and eva2
Expand All @@ -187,19 +190,13 @@ def fetch_and_update_positions():

features = []

# Spoof and convert positions if they are zero
for idx, (name, pos) in enumerate(positions.items()):
posx, posy = pos["posx"], pos["posy"]

if posx == 0 and posy == 0:
latitude = 29.564802807347508
longitude = -95.08160677610833
utm_coords = utm.from_latlon(latitude, longitude)
# posx = utm_coords[0] + random.uniform(-30, 30)
# posy = utm_coords[1] + random.uniform(-30, 30)
# print(f"Spoofed position data for {name}")

lat, lon = utm_to_latlon(posx, posy, utm_coords[2], utm_coords[3])
# Assuming a default UTM zone for this example
zone_number = 15
zone_letter = 'R'
lat, lon = utm_to_latlon(posx, posy, zone_number, zone_letter)

feature = {
"type": "Feature",
Expand All @@ -219,11 +216,10 @@ def fetch_and_update_positions():
with open(CURRENT_LOCATIONS_FILE, "w") as f:
dump(feature_collection, f)

print(f"Updated CURRENT_LOCATIONS.geojson with new positions for rover, eva1, and eva2")
return (f"Updated CURRENT_LOCATIONS.geojson with new positions for rover, eva1, and eva2")

except Exception as e:
print(f"Error fetching or updating positions: {e}")

return (f"Error fetching or updating positions: {e}")

# Save new IP or Key
@app.put("/update_config")
Expand Down
20 changes: 18 additions & 2 deletions src/components/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ const MapboxComponent = ({ zoom = 17 }) => {
};

fetchGeoJSON();
const intervalId = setInterval(fetchGeoJSON, 1000);
return () => clearInterval(intervalId);
const intervalIdGeoJSON = setInterval(fetchGeoJSON, 1000);
return () => clearInterval(intervalIdGeoJSON);
});

newMap.on('click', (e) => {
Expand All @@ -111,6 +111,22 @@ const MapboxComponent = ({ zoom = 17 }) => {
}
}, [mapBoxAPIKey, zoom]);

useEffect(() => {
const fetchUpdatePositions = async () => {
try {
const response = await fetch("http://localhost:8000/update_positions");
const data = await response.json();
console.log("Updated Positions:", data);
} catch (error) {
console.error("Error updating positions:", error);
}
};

fetchUpdatePositions();
const intervalIdUpdatePositions = setInterval(fetchUpdatePositions, 3000);
return () => clearInterval(intervalIdUpdatePositions);
}, []);

const hideModal = () => setModalVisible(false);

const handleAddPoint = async ({ name, id, coordinates }) => {
Expand Down

0 comments on commit 674996b

Please sign in to comment.