AtsushiSakai/PythonRobotics · error · TypeError
robot_type must be an instance of RobotType
Error message
robot_type must be an instance of RobotType
What it means
Raised by the robot_type property setter on Config when assigned a value that is not a RobotType enum instance. The config enforces type safety because downstream DWA logic branches on the specific robot type.
Source
Thrown at PathPlanning/DynamicWindowApproach/dynamic_window_approach.py:88
[5.0, 9.0],
[8.0, 9.0],
[7.0, 9.0],
[8.0, 10.0],
[9.0, 11.0],
[12.0, 13.0],
[12.0, 12.0],
[15.0, 15.0],
[13.0, 13.0]
])
@property
def robot_type(self):
return self._robot_type
@robot_type.setter
def robot_type(self, value):
if not isinstance(value, RobotType):
raise TypeError("robot_type must be an instance of RobotType")
self._robot_type = value
config = Config()
def motion(x, u, dt):
"""
motion model
"""
x[2] += u[1] * dt
x[0] += u[0] * math.cos(x[2]) * dt
x[1] += u[0] * math.sin(x[2]) * dt
x[3] = u[0]
x[4] = u[1]
return xView on GitHub (pinned to 1fe4fb980f)
Solutions
- Assign the enum: from dynamic_window_approach import RobotType; config.robot_type = RobotType.cycle.
- Convert loaded strings: RobotType[value_str] or RobotType(value_str).
- Keep config serialization/deserialization enum-aware (e.g. save .value, load by name).
Example fix
# before config.robot_type = 'diff' # string # after config.robot_type = RobotType.diff
Defensive patterns
Strategy: type-guard
Validate before calling
from PathPlanning.DynamicWindowApproach.dynamic_window_approach import RobotType assert isinstance(cfg_value, RobotType) or cfg_value in [m.value for m in RobotType]
Type guard
from PathPlanning.DynamicWindowApproach.dynamic_window_approach import RobotType
def to_robot_type(v):
return v if isinstance(v, RobotType) else RobotType[v] if v in RobotType.__members__ else RobotType(v) Prevention
- Convert config-file strings to enums at load time (RobotType[name]).
- Store enum .value when serializing configs.
When it happens
Trigger: Assigning config.robot_type = 'omnidirectional' (string) or config.robot_type = 1 instead of a RobotType member like RobotType.cycle.
Common situations: Loading config values from YAML/JSON where enums deserialize as strings, or porting config code that previously used plain strings.
Related errors
AI-assisted analysis of AtsushiSakai/PythonRobotics@1fe4fb980f (2026-08-28).
Data as JSON: /api/errors/9f245ea82f6be30d.
Report an issue: GitHub.