Description
Check here first
Describe the bug
When using the RandomPath
driver and running a robot simulation, a RuntimeError
is raised when attempting to update the goal marker position: RuntimeError: x must be a sequence
Version information
Did you install from PyPI or GitHub?
- Installed from: PyPI(pip install rvc3python)
- Robotics Toolbox version: 1.1.1
- Swift: 1.1.0
- SpatialMath toolbox: version 1.1.14
Robotics Toolbox depends heavily on two other packages: Swift (3D graphics) and SpatialMath toolbox (underpinning maths utilities). If you think your issue is related to these, then please answer the questions above for them.
To Reproduce
Example code:
import numpy as np
from spatialmath import *
from spatialmath.base import *
from roboticstoolbox import *
V = np.diag([0.02, np.deg2rad(0.5)]) ** 2
robot = Bicycle(covar=V, animation="car")
robot.control = RandomPath(workspace=10)
robot.run(T=10);
Output:
(rvc-sim) PS D:\repos\rvc-sim> & d:/repos/rvc-sim/.venv/Scripts/python.exe d:/repos/rvc-sim/temp.py
Traceback (most recent call last):
File "d:\repos\rvc-sim\temp.py", line 9, in <module>
robot.run(T=10);
File "D:\repos\rvc-sim\.venv\lib\site-packages\roboticstoolbox\mobile\Vehicle.py", line 460, in run
self.step(animate=animate)
File "D:\repos\rvc-sim\.venv\lib\site-packages\roboticstoolbox\mobile\Vehicle.py", line 672, in step
u = self.eval_control(self._control, self._x)
File "D:\repos\rvc-sim\.venv\lib\site-packages\roboticstoolbox\mobile\Vehicle.py", line 330, in eval_control
u = control.demand()
File "D:\repos\rvc-sim\.venv\lib\site-packages\roboticstoolbox\mobile\drivers.py", line 233, in demand
self._new_goal()
File "D:\repos\rvc-sim\.venv\lib\site-packages\roboticstoolbox\mobile\drivers.py", line 275, in _new_goal
self._goal_marker.set_xdata(self._goal[0])
File "D:\repos\rvc-sim\.venv\lib\site-packages\matplotlib\lines.py", line 1304, in set_xdata
raise RuntimeError('x must be a sequence')
RuntimeError: x must be a sequence
Expected behavior
The simulation should be started correctly.
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
- Windows
- Python 3.10.11
Additional context
The error occurs because matplotlib.lines.Line2D.set_xdata()
expects an iterable input (like a list or array), but a scalar value was passed instead.
Temporary fix:
In drivers.py
, locate the RandomPath._new_goal()
method and change:
self._goal_marker.set_xdata(self._goal[0])
self._goal_marker.set_ydata(self._goal[1])
to:
self._goal_marker.set_xdata([self._goal[0]])
self._goal_marker.set_ydata([self._goal[1]])
This ensures compatibility with Matplotlib's plotting interface and avoids the runtime error.