Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARMA Messenger Integration Test #231

Merged
merged 17 commits into from
Jan 6, 2025
Merged

Conversation

chengyuan0124
Copy link
Contributor

@chengyuan0124 chengyuan0124 commented Dec 16, 2024

PR Details

The update is for the integration testing CXC-118

Related GitHub Issue

Related Jira Key

Motivation and Context

How Has This Been Tested?

Types of changes

  • Defect fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that cause existing functionality to change)

Checklist:

  • I have added any new packages to the sonar-scanner.properties file
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@chengyuan0124 chengyuan0124 requested a review from kjrush December 20, 2024 16:58
@@ -34,6 +34,8 @@ def __init__(self, sumo_connector, veh_id):
self.sumo_connector = sumo_connector
self.sumo_connector.create_stop_veh(self._target_veh_id, self._stop_pos, self._stop_route)
self.first_time_two_vehicles = True
self.is_get_closer = False
Copy link
Contributor

@kjrush kjrush Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not advocating for any kind of change, but wanted to point out some thoughts for future cases like this:

Generally at a design level, this is where something like a state machine would be good to consider. Right now you've got two variables is_get_closer and is_stopped (and possibly others here) that are really representing a single underlying state of the algorithm. The key is that these two variables are mutually exclusive, as far as I can tell, that the is_get_closer should never be true while is_stopped is true, and vice-versa. So they really encode an aspect of a single actual piece of information, having them as two separate variables like this doesn't really enforce or communicate that relationship between them.

A state machine implementation for something like this could be as simple as identifying the states of the algorithm and then defining an enum with a value per state:

class MoveOverLawState(Enum):
  INIT = 1
  GET_CLOSER = 2
  STOPPING = 3
  STOPPED = 4
  DEPART = 5

and then tracking it as a single self.state variable. This way you represent that there is really only one state value at a time (rather than two truly independent variables) and represented the total possible state space within that one variable. You could then design the class in a way that uses a switch statement or different methods per state, define transition conditions for each possible transition within the state space, etc.

def process():
  if self.state == INIT:
    do_init()
    if should_transition_to_approaching(): 
      self.state = APPROACHING
  elif self.state == APPROACHING:
    do_approaching()
    if should_transition_to_stopping();
      self.state = STOPPING
  #etc, etc.

The value of that depends on how complex the design is, probably not necessary for this particular example.

vehID=veh_id, # Vehicle ID
edgeID=traci.vehicle.getRoadID(veh_id), # Edge ID where the vehicle stops
pos=70, # Position (meters) on the edge
laneIndex=2, # Lane index (e.g., 0 for the first lane)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pos and laneIndex seem hard coded? Will this work for other scenarios?

@@ -257,7 +267,7 @@ def get_veh_pos(self, veh_id):

def create_stop_veh(self, veh_id, end_pos, stop_route):
try:
traci.vehicle.add(vehID = veh_id, routeID=stop_route, typeID="car", depart=0, departPos=end_pos)
traci.vehicle.add(vehID = veh_id, routeID=stop_route, typeID="car", depart=0, departPos=end_pos, departLane='2')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as comment above re hard-coding

@@ -36,34 +36,35 @@ public class CarmaMessageAmbassador extends CommonMessageAmbassador<CarmaInstanc
private Thread registrationRxBackgroundThread;
private CarmaV2xMessageReceiver v2xMessageReceiver;
private Thread v2xRxBackgroundThread;
private CarmaInstanceManager carmaInstanceManager;
private static CarmaInstanceManager carmaInstanceManager = new CarmaInstanceManager();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static is a weird access modifier for this. Is there a case where we need to access this carmaInstanceManager instance variable w/o actually having a constructed instance of the CarmaMessageAmbassador? That'd strike me as kind of off without further context, so I'd be curious to see where that arises if so.

Copy link

sonarqubecloud bot commented Jan 6, 2025

@EricChen-Lei EricChen-Lei requested a review from kjrush January 6, 2025 18:45
@EricChen-Lei EricChen-Lei merged commit 9e1126e into develop Jan 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants