1
1
#!/usr/bin/env python3
2
2
3
- from autonav_msgs .msg import Position , IMUData , PathingDebug
3
+ from autonav_msgs .msg import Position , IMUData , PathingDebug , SafetyLights
4
4
from scr_msgs .msg import SystemState
5
5
from scr_core .node import Node
6
6
from scr_core .state import DeviceStateEnum , SystemStateEnum , SystemMode
50
50
[(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 )],
51
51
]
52
52
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
+
53
70
54
71
class AStarNode (Node ):
55
72
def __init__ (self ):
@@ -65,9 +82,12 @@ def configure(self):
65
82
self .imuSubscriber = self .create_subscription (IMUData , "/autonav/imu" , self .onImuReceived , 20 )
66
83
self .debugPublisher = self .create_publisher (PathingDebug , "/autonav/debug/astar" , 20 )
67
84
self .pathPublisher = self .create_publisher (Path , "/autonav/path" , 20 )
85
+ self .safetyLightsPublisher = self .create_publisher (SafetyLights , "/autonav/SafetyLights" , 20 )
68
86
self .pathDebugImagePublisher = self .create_publisher (CompressedImage , "/autonav/debug/astar/image" , 20 )
69
87
self .mapTimer = self .create_timer (0.1 , self .createPath )
70
88
89
+ self .resetWhen = - 1.0
90
+
71
91
self .config .setFloat (CONFIG_WAYPOINT_POP_DISTANCE , 1.5 )
72
92
self .config .setInt (CONFIG_WAYPOINT_DIRECTION , 0 )
73
93
self .config .setBool (CONFIG_USE_ONLY_WAYPOINTS , False )
@@ -235,6 +255,10 @@ def onConfigSpaceReceived(self, msg: OccupancyGrid):
235
255
pathingDebug .time_until_use_waypoints = time_remaining
236
256
self .debugPublisher .publish (pathingDebug )
237
257
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
+
238
262
if len (self .waypoints ) > 0 :
239
263
next_waypoint = self .waypoints [0 ]
240
264
north_to_gps = (next_waypoint [0 ] - self .position .latitude ) * self .latitudeLength
@@ -243,6 +267,8 @@ def onConfigSpaceReceived(self, msg: OccupancyGrid):
243
267
244
268
if north_to_gps ** 2 + west_to_gps ** 2 <= self .config .getFloat (CONFIG_WAYPOINT_POP_DISTANCE ):
245
269
self .waypoints .pop (0 )
270
+ self .safetyLightsPublisher .publish (toSafetyLights (True , False , 2 , 255 , "#00FF00" ))
271
+ self .resetWhen = time .time () + 1.5
246
272
247
273
pathingDebug = PathingDebug ()
248
274
pathingDebug .desired_heading = heading_to_gps
0 commit comments