Skip to content

Commit

Permalink
Rename symbol to use singular waypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruishenl committed Jan 19, 2024
1 parent 3bca4c2 commit 55572c2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
1 change: 1 addition & 0 deletions invertedai/api/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def drive(
List of agent attributes. Each agent requires, length: [float]
width: [float] and rear_axis_offset: [float] all in meters. agent_type: [str],
currently supports 'car' and 'pedestrian'.
waypoint: optional [Point], the target waypoint of the agent.
recurrent_states:
Recurrent states for all agents, obtained from the previous call to
Expand Down
1 change: 1 addition & 0 deletions invertedai/api/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def initialize(
agent_attributes:
Static attributes for all agents.
The pre-defined agents should be specified first, followed by the sampled agents.
The optional waypoint passed will be ignored for Initialize.
states_history:
History of pre-defined agent states - the outer list is over time and the inner over agents,
Expand Down
22 changes: 11 additions & 11 deletions invertedai/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,28 @@ class AgentAttributes(BaseModel):
#: Distance from the agent's center to its rear axis in meters. Determines motion constraints.
rear_axis_offset: Optional[float] = None
agent_type: Optional[str] = 'car' #: Valid types are those in `AgentType`, but we use `str` here for extensibility.
waypoints: Optional[Point] = None #: Target waypoint of the agent. If provided the agent will attempt to reach it.
waypoint: Optional[Point] = None #: Target waypoint of the agent. If provided the agent will attempt to reach it.

@classmethod
def fromlist(cls, l):
if len(l) == 5:
length, width, rear_axis_offset, agent_type, waypoints = l
return cls(length=length, width=width, rear_axis_offset=rear_axis_offset, agent_type=agent_type, waypoints=Point(x=waypoints[0], y=waypoints[1]))
length, width, rear_axis_offset, agent_type, waypoint = l
return cls(length=length, width=width, rear_axis_offset=rear_axis_offset, agent_type=agent_type, waypoints=Point(x=waypoint[0], y=waypoint[1]))
if len(l) == 4:
if type(l[3]) == list:
if type(l[2]) == str:
length, width, agent_type, waypoints = l
return cls(length=length, width=width, agent_type=agent_type, waypoints=Point(x=waypoints[0], y=waypoints[1]))
length, width, agent_type, waypoint = l
return cls(length=length, width=width, agent_type=agent_type, waypoints=Point(x=waypoint[0], y=waypoint[1]))
else:
length, width, rear_axis_offset, waypoints = l
return cls(length=length, width=width, rear_axis_offset=rear_axis_offset, waypoints=Point(x=waypoints[0], y=waypoints[1]))
length, width, rear_axis_offset, waypoint = l
return cls(length=length, width=width, rear_axis_offset=rear_axis_offset, waypoints=Point(x=waypoint[0], y=waypoint[1]))
else:
length, width, rear_axis_offset, agent_type = l
return cls(length=length, width=width, rear_axis_offset=rear_axis_offset, agent_type=agent_type)
elif len(l) == 3:
if type(l[2]) == list:
length, width, waypoints = l
return cls(length=length, width=width, waypoints=Point(x=waypoints[0], y=waypoints[1]))
length, width, waypoint = l
return cls(length=length, width=width, waypoint=Point(x=waypoint[0], y=waypoint[1]))
elif type(l[2]) == str:
length, width, agent_type = l
return cls(length=length, width=width, agent_type=agent_type)
Expand All @@ -212,8 +212,8 @@ def tolist(self):
attr_list.append(self.rear_axis_offset)
if self.agent_type is not None:
attr_list.append(self.agent_type)
if self.waypoints is not None:
attr_list.append([self.waypoints.x, self.waypoints.y])
if self.waypoint is not None:
attr_list.append([self.waypoint.x, self.waypoint.y])
return attr_list


Expand Down
21 changes: 8 additions & 13 deletions invertedai_cpp/invertedai/data_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ struct AgentAttributes {
/**
* Target waypoint of the agent. If provided the agent will attempt to reach it.
*/
std::optional<Point2d> waypoints;

void setWaypoints(double x, double y)
{
waypoints = Point2d{x, y};
}
std::optional<Point2d> waypoint;

void printFields() const {
std::cout << "checking fields of current agent..." << std::endl;
Expand All @@ -88,8 +83,8 @@ struct AgentAttributes {
if (agent_type.has_value()) {
std::cout << "Agent type: " << agent_type.value() << std::endl;
}
if (waypoints.has_value()) {
std::cout << "Waypoints: (" << waypoints.value().x << "," << waypoints.value().y << ")"<< std::endl;
if (waypoint.has_value()) {
std::cout << "Waypoints: (" << waypoint.value().x << "," << waypoint.value().y << ")"<< std::endl;
}
}

Expand All @@ -108,8 +103,8 @@ struct AgentAttributes {
attr_vector.push_back(agent_type.value());
}
std::vector<std::vector<double>> waypoint_vector;
if (waypoints.has_value()) {
waypoint_vector.push_back({waypoints.value().x, waypoints.value().y});
if (waypoint.has_value()) {
waypoint_vector.push_back({waypoint.value().x, waypoint.value().y});
}
json jsonArray = json::array();
for (const auto &element : attr_vector) {
Expand Down Expand Up @@ -137,7 +132,7 @@ struct AgentAttributes {
rear_axis_offset = element[2];
}
else if (element[2].is_array()) {
waypoints = {element[2][0], element[2][1]};
waypoint = {element[2][0], element[2][1]};
}
length = element[0];
width = element[1];
Expand All @@ -148,7 +143,7 @@ struct AgentAttributes {
width = element[1];
if (element[3].is_array())
{
waypoints = {element[3][0], element[3][1]};
waypoint = {element[3][0], element[3][1]};
if (element[2].is_string())
{
agent_type = element[2];
Expand Down Expand Up @@ -191,7 +186,7 @@ struct AgentAttributes {
if (element[3].is_string()) {
agent_type = element[3];
}
waypoints = {element[4][0], element[4][1]};
waypoint = {element[4][0], element[4][1]};
}
}
};
Expand Down

0 comments on commit 55572c2

Please sign in to comment.