diff --git a/invertedai/api/drive.py b/invertedai/api/drive.py index c7f3cb5b..08523c6b 100644 --- a/invertedai/api/drive.py +++ b/invertedai/api/drive.py @@ -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 diff --git a/invertedai/api/initialize.py b/invertedai/api/initialize.py index 9117b6e0..05c4abfb 100644 --- a/invertedai/api/initialize.py +++ b/invertedai/api/initialize.py @@ -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, diff --git a/invertedai/common.py b/invertedai/common.py index 20b504c5..40bdfd19 100644 --- a/invertedai/common.py +++ b/invertedai/common.py @@ -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) @@ -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 diff --git a/invertedai_cpp/invertedai/data_utils.h b/invertedai_cpp/invertedai/data_utils.h index b439a583..bbdcd3b2 100644 --- a/invertedai_cpp/invertedai/data_utils.h +++ b/invertedai_cpp/invertedai/data_utils.h @@ -67,12 +67,7 @@ struct AgentAttributes { /** * Target waypoint of the agent. If provided the agent will attempt to reach it. */ - std::optional waypoints; - - void setWaypoints(double x, double y) - { - waypoints = Point2d{x, y}; - } + std::optional waypoint; void printFields() const { std::cout << "checking fields of current agent..." << std::endl; @@ -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; } } @@ -108,8 +103,8 @@ struct AgentAttributes { attr_vector.push_back(agent_type.value()); } std::vector> 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) { @@ -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]; @@ -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]; @@ -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]}; } } };