-
Notifications
You must be signed in to change notification settings - Fork 71
Description
I think this is serious, but it needs independent corroboration.
If the user carelessly provides integer values for the initial_conditions when creating a RobotariumABC object, deep magic in Numpy can make the dynamics break. To save careless users (like my past self) from this, I suggest changing the definition of the variable self.initial_conditions in the __init__ method of this class. Right now this is line 33 in the file named robotarium_abc.py, and it makes a literal copy of the user input. I think that line should be replaced with this:
self.initial_conditions = initial_conditions.astype(float)
Here is a test case to copy-paste into the Python simulator and demonstrate the issue. Toggle the line after N=1. Then make the change suggested above and retest. Finally, check that the suggested change doesn't break something else.
import rps.robotarium as robotarium
from rps.utilities.transformations import *
from rps.utilities.barrier_certificates import *
from rps.utilities.misc import *
from rps.utilities.controllers import *
import numpy as np
import time
N = 1 # Number of Robots
# Activate one of the following two lines and observe the different outcomes
#init_pos = np.array([-1.3,0,0]).reshape(3,1) # Initial Positions - works!
init_pos = np.array([-1,0,0]).reshape(3,1) # Initial Positions are all integers - breaks!
iterations = 60 # Run the simulation/experiment for 60 steps
r = robotarium.Robotarium(number_of_robots=N, show_figure=True, initial_conditions=init_pos, sim_in_real_time=True)
line_width = 5 # Big lines
position_history = np.empty((2,0)) # History to show what the robot does
r.axes.plot([-1.6,1.6],[0,0],linewidth=line_width,color='k',zorder=-1) # Plot reference line
for t in range(iterations):
x = r.get_poses() # Get the poses of robots
dxu = np.array([0.15,0]).reshape(2,1) # Define the Speed of the robot
r.set_velocities(np.arange(N), dxu) # Set the velocities using unicycle commands
print(f"Index t={t:3d}: pose {x[0,0]:4.2f} {x[1,0]:4.2f} {x[2,0]:4.2f}; inputs {dxu[0,0]:4.2f}, {dxu[1,0]:4.2f}.")
# Plotting the robot's true trajectory.
position_history=np.append(position_history, x[:2],axis=1)
if(t == iterations-1):
r.axes.scatter(position_history[0,:],position_history[1,:], s=1, linewidth=line_width, color='r', linestyle='dashed')
r.step() # Iterate the simulation
secretx = r.poses
print(f" Updated pose: {secretx[0,0]:4.2f} {secretx[1,0]:4.2f} {secretx[2,0]:4.2f}.")
time.sleep(5)
r.call_at_scripts_end() # Call at end of script to print debug information
Thanks for considering this.