Skip to content

Commit dcc927a

Browse files
committed
Added safety lights to astar and fixed mob start issue
1 parent d479515 commit dcc927a

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

autonav_ws/src/autonav_nav/src/astar.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
from autonav_msgs.msg import Position, IMUData, PathingDebug
3+
from autonav_msgs.msg import Position, IMUData, PathingDebug, SafetyLights
44
from scr_msgs.msg import SystemState
55
from scr_core.node import Node
66
from scr_core.state import DeviceStateEnum, SystemStateEnum, SystemMode
@@ -50,6 +50,23 @@
5050
[(35.19496918, -97.43855286), (35.19498780, -97.43859524), (35.19495163, -97.43871339), (35.19495182, -97.43877829), (35.19493406, -97.43879432), (35.19493812, -97.43881810), (35.19495368, -97.43882411), (35.19493357, -97.43902773), (35.19485847, -97.43902381)],
5151
]
5252

53+
def hexToRgb(color: str):
54+
if color[0] == "#":
55+
color = color[1:]
56+
return [int(color[0:2], 16), int(color[2:4], 16), int(color[4:6], 16)]
57+
58+
def toSafetyLights(autonomous: bool, eco: bool, mode: int, brightness: int, color: str) -> SafetyLights:
59+
pkg = SafetyLights()
60+
pkg.mode = mode
61+
pkg.autonomous = autonomous
62+
pkg.eco = eco
63+
pkg.brightness = brightness
64+
colorr = hexToRgb(color)
65+
pkg.red = colorr[0]
66+
pkg.green = colorr[1]
67+
pkg.blue = colorr[2]
68+
return pkg
69+
5370

5471
class AStarNode(Node):
5572
def __init__(self):
@@ -65,9 +82,12 @@ def configure(self):
6582
self.imuSubscriber = self.create_subscription(IMUData, "/autonav/imu", self.onImuReceived, 20)
6683
self.debugPublisher = self.create_publisher(PathingDebug, "/autonav/debug/astar", 20)
6784
self.pathPublisher = self.create_publisher(Path, "/autonav/path", 20)
85+
self.safetyLightsPublisher = self.create_publisher(SafetyLights, "/autonav/SafetyLights", 20)
6886
self.pathDebugImagePublisher = self.create_publisher(CompressedImage, "/autonav/debug/astar/image", 20)
6987
self.mapTimer = self.create_timer(0.1, self.createPath)
7088

89+
self.resetWhen = -1.0
90+
7191
self.config.setFloat(CONFIG_WAYPOINT_POP_DISTANCE, 1.5)
7292
self.config.setInt(CONFIG_WAYPOINT_DIRECTION, 0)
7393
self.config.setBool(CONFIG_USE_ONLY_WAYPOINTS, False)
@@ -235,6 +255,10 @@ def onConfigSpaceReceived(self, msg: OccupancyGrid):
235255
pathingDebug.time_until_use_waypoints = time_remaining
236256
self.debugPublisher.publish(pathingDebug)
237257

258+
if time.time() > self.resetWhen and self.resetWhen != -1:
259+
self.safetyLightsPublisher.publish(toSafetyLights(True, False, 2, 255, "#FFFFFF"))
260+
self.resetWhen = -1
261+
238262
if len(self.waypoints) > 0:
239263
next_waypoint = self.waypoints[0]
240264
north_to_gps = (next_waypoint[0] - self.position.latitude) * self.latitudeLength
@@ -243,6 +267,8 @@ def onConfigSpaceReceived(self, msg: OccupancyGrid):
243267

244268
if north_to_gps ** 2 + west_to_gps ** 2 <= self.config.getFloat(CONFIG_WAYPOINT_POP_DISTANCE):
245269
self.waypoints.pop(0)
270+
self.safetyLightsPublisher.publish(toSafetyLights(True, False, 2, 255, "#00FF00"))
271+
self.resetWhen = time.time() + 1.5
246272

247273
pathingDebug = PathingDebug()
248274
pathingDebug.desired_heading = heading_to_gps

autonav_ws/src/autonav_nav/src/path_resolver.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def onReset(self):
7070
def transition(self, old: SystemState, updated: SystemState):
7171
if updated.state == SystemStateEnum.AUTONOMOUS and self.getDeviceState() == DeviceStateEnum.READY:
7272
self.setDeviceState(DeviceStateEnum.OPERATING)
73+
if updated.mobility:
74+
self.safetyLightsPublisher.publish(toSafetyLights(True, False, 2, 255, "#FFFFFF"))
75+
else:
76+
self.safetyLightsPublisher.publish(toSafetyLights(False, False, 2, 255, "#00A36C"))
7377

7478
if updated.state != SystemStateEnum.AUTONOMOUS and self.getDeviceState() == DeviceStateEnum.OPERATING:
7579
self.setDeviceState(DeviceStateEnum.READY)

tests/pfilter/multirun.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import numpy as np
2+
from typies import Feedback, GPS
3+
import matplotlib.pyplot as plt
4+
import math
5+
import os
6+
7+
HOME_DIR = os.path.expanduser("~")
8+
FOLDER = os.path.join(HOME_DIR, "day1")
9+
10+
runs = {}
11+
# For each folder, create a new run
12+
for folder in os.listdir(FOLDER):
13+
if folder.startswith("run"):
14+
run = folder
15+
runs[run] = []
16+
17+
# Read the ENTRY_GPS.csv file
18+
gps_file = os.path.join(FOLDER, folder, "ENTRY_POSITION.csv")
19+
with open(gps_file, "r") as f:
20+
lines = f.readlines()
21+
for line in lines:
22+
lat = float(line.split(",")[5])
23+
lon = float(line.split(",")[6])
24+
runs[run].append((lat, lon))
25+
26+
for run in runs:
27+
lats = [gps[0] for gps in runs[run]]
28+
lons = [gps[1] for gps in runs[run]]
29+
plt.plot(lons, lats, label=run)
30+
31+
waypoints = [(42.6682697222 ,-83.2193403028),(42.6681206444,-83.2193606083),(42.6680766333,-83.2193591583),(42.6679277056,-83.2193276417), (42.6681268, -83.218887)]
32+
# Plot as dots
33+
lats = [gps[0] for gps in waypoints]
34+
lons = [gps[1] for gps in waypoints]
35+
plt.plot(lons, lats, "o", label="Waypoints")
36+
37+
plt.legend()
38+
plt.show()

0 commit comments

Comments
 (0)