Skip to content

Commit c3f2cfc

Browse files
committed
HW1 Part1.2
1 parent 2f1b7e7 commit c3f2cfc

4 files changed

Lines changed: 28 additions & 23 deletions

File tree

GEMstack/knowledge/defaults/computation_graph.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ components:
4949
- motion_planning:
5050
inputs: all
5151
outputs: trajectory
52-
- trajectory_tracking:
53-
inputs: [vehicle, trajectory]
54-
outputs:
52+
- signaline:
53+
inputs: intent
54+
outputs: []

GEMstack/onboard/planning/blink_component.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from ..component import Component
22
from ..interface.gem import GEMInterface,GEMVehicleCommand,GEMVehicleReading
33
import time
4+
from ...state import AllState, VehicleIntentEnum
45

56
TURN_OFF = 0
67
TURN_LEFT = 1
@@ -19,7 +20,7 @@ def __init__(self, vehicle_interface : GEMInterface):
1920
def rate(self):
2021
"""Requested update frequency, in Hz"""
2122
return 0.5
22-
23+
2324
def initialize(self):
2425
"""Run first"""
2526
print("BlinkDistress Component Initialized.")
@@ -32,28 +33,31 @@ def cleanup(self):
3233
self.send_turn_command(TURN_OFF)
3334
# pass
3435

35-
def update(self):
36+
def update(self, intent):
3637
"""Run in a loop"""
3738
# we need to set up a GEMVehicleCommand which encapsulates all commands that will be
3839
# sent to the drive-by-wire system, simultaneously. To avoid doing arbitrary things
3940
# to the vehicle, let's maintain the current values (e.g., accelerator, brake pedal,
4041
# steering angle) from its current readings.
41-
current_time = time.time()
42-
if current_time - self.last_update_time >= 2: # Change signal every 2 seconds
43-
if self.turn_state == TURN_OFF:
44-
self.turn_state = TURN_LEFT
45-
elif self.turn_state == TURN_LEFT:
46-
self.turn_state = TURN_RIGHT
47-
else:
48-
self.turn_state = TURN_OFF
42+
if intent.intent == VehicleIntentEnum.HALTING:
43+
current_time = time.time()
44+
if current_time - self.last_update_time >= 2: # Change signal every 2 seconds
45+
if self.turn_state == TURN_OFF:
46+
self.turn_state = TURN_LEFT
47+
elif self.turn_state == TURN_LEFT:
48+
self.turn_state = TURN_RIGHT
49+
else:
50+
self.turn_state = TURN_OFF
4951

50-
self.send_turn_command(self.turn_state)
51-
self.last_update_time = current_time
52-
52+
self.send_turn_command(self.turn_state)
53+
self.last_update_time = current_time
54+
else:
55+
self.send_turn_command(TURN_OFF)
56+
5357
# Read vehicle sensor data
5458
vehicle_reading = self.vehicle_interface.get_reading()
5559
print(f"Vehicle Speed: {vehicle_reading.speed:.2f} m/s")
56-
print(f"Acceleration: {vehicle_reading.accelerator_pedal_position - vehicle_reading.brake_pedal_position:.2f} m/s²")
60+
print(f"Acceleration: {vehicle_reading.accelerator_pedal_position - vehicle_reading.brake_pedal_position:.2f} m/²")
5761
# command = self.vehicle_interface.command_from_reading()
5862
# TODO: alter command to execute turn signals, then uncomment line below to send
5963
# the command to vehicle
@@ -80,5 +84,4 @@ def send_turn_command(self, turn_signal):
8084

8185
def healthy(self):
8286
"""Returns True if the element is in a stable state."""
83-
return True
84-
87+
return True

homework/blink.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def run_ros_loop(node):
109109
termination_reason = "undetermined"
110110
try:
111111
while not rospy.is_shutdown() and not node.done() and node.healthy():
112-
node.update()
112+
node.update(node.state_inputs())
113113
rate.sleep()
114114
if node.done():
115115
termination_reason = "Node done"

launch/blink_launch.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ recovery:
99
state_estimation : GNSSStateEstimator
1010
perception_normalization : StandardPerceptionNormalizer
1111
planning:
12-
trajectory_tracking : blink_component.BlinkDistress
12+
# trajectory_tracking : blink_component.BlinkDistress
13+
signaling : blink_component.BlinkDistress
1314
# Driving behavior for the GEM vehicle. Runs perception and planner but doesn't execute anything (no controller).
1415
drive:
1516
perception:
1617
state_estimation : GNSSStateEstimator
1718
perception_normalization : StandardPerceptionNormalizer
1819
planning:
19-
trajectory_tracking : blink_component.BlinkDistress
20+
# trajectory_tracking : blink_component.BlinkDistress
21+
signaling : blink_component.BlinkDistress
2022
log:
2123
# Specify the top-level folder to save the log files. Default is 'logs'
2224
folder : 'logs'
@@ -61,4 +63,4 @@ variants:
6163
state_estimation : OmniscientStateEstimator
6264
drive:
6365
perception:
64-
state_estimation : OmniscientStateEstimator
66+
state_estimation : OmniscientStateEstimator

0 commit comments

Comments
 (0)