jdelacroix / simiam

A MATLAB-based educational bridge between theory and practice in robotics.
http://gritslab.gatech.edu/projects/robot-simulator
Other
103 stars 52 forks source link

Can you provide me a map of your clesses? #2

Closed BlueBirdHouse closed 10 years ago

BlueBirdHouse commented 10 years ago

Can you provide me a map of your clesses? You have built so many clesses, I do not understand what are they doing. A map will be helpful. We have three of K3 robot in our lab.

jdelacroix commented 10 years ago

I don't have a UML diagram on hand to share, but I can summarize how the simulator works:

  1. launch.m sets up the paths and creates UI, which is defined in simiam.ui.AppWindow. The simiam.ui packages also includes other classes that draw objects (robots and obstacles) in the environment. For example, simiam.ui.Drawable is the base object for anything that can be drawn in the simulator, and each Drawable is made up of one or many simiam.ui.Surface2D objects, which define the 2D shape of the Drawable.
  2. When the user clicks the "Play" button in the UI, the ui_button_start() function creates a new instance of the simulator from simiam.simulator.Simulator. It also creates a simiam.simulator.World for the simulator from the settings.xml file. This file specifies all objects that should be created in the simulator, such as robots and obstacles. The settings.xml file specifies an application (simiam.app) to run, and also specifies which type of supervisor is attached to the robot (simiam.controller.supervisor). For example, settings.xml in the master branch specifies two Khepera3 robots that both use the same supervisor.
  3. Robots are defined in the simiam.robot package. simiam.robot.Robot is the template and simiam.robot.Khepera3 is an implementation of a robot. The simiam.robot.dynamics and simiam.robot.sensor subpackages define the different sensors and dynamics that a robot can use. For example, the simiam.robot.Khepera3 class makes use of simiam.robot.sensors.ProximitySensor to add nine IR proximity sensors to the robot.
  4. A simiam.simulator.Simulator object has a timer, which calls the simulator's step() function every time_step seconds.
  5. This step() function first iterates over every robot and executes each robot's supervisor. The supervisor can be thought of as a decision maker. For example, it may define a finite state machine, which decides which controller to execute. Typically, the supervisor picks a controller (any controller defined in the simiam.controller package) and calls the controller's execute function with some inputs. The controller takes in the inputs and returns outputs (usually the desired linear and angular velocity of the robot). The supervisor takes the outputs and converts them to the left and right angular wheel speeds, which are passed to the robot via the set_wheel_speeds() function. Finally, the supervisor calls the update_odometry() function to update the estimate of the robot's pose based on output from the wheel encoders.
  6. Then, the supervisor returns from its execute() function, and the simulator's step() function moves on to update the state of the robot via update_state(). This function takes in the current actual pose (not estimated!) of the robot and applies the dynamics of the robot to compute the new pose of the robot for the next time step based on the left and right wheel speeds of the robot.
  7. The step() function then calls the run() function in the app. The app has access to all robots in the simulator and can interact with events in the UI. For example, an app may be used to capture mouse clicks in the UI and set the location of the mouse click to the goal location for a robot.
  8. After the app is done, the step() function calls the apply_physics() function in the simiam.simulator.Physics class. This function is responsible for a) checking if the robot has collided with any obstacles, and b) see if the footprints of the proximity sensors intersect with any obstacles (if so, set the output of the senor to the distance between the sensor and the intersected obstacle).
  9. Last, the step() function calls ui_update(), which updates the UI based on the state of the simulator. For example, the clock is updated and the simulator is stopped if any robot has collided with an obstacle.
  10. Steps 5-9 are repeated at each time step until the simulation stops.

These steps cover all of the classes used in the simulator, except for classes defined in the simiam.containers and simiam.util packages. The former package contains any data structures used in the simulator, while the latter package currently contains the Plotter class. The Plotter class is used by the supervisor and classes to provide visual feedback on what the robot is doing versus what the controllers determine the robot should be doing.

I hope this explanation clears up how the classes work together. If you have any specific questions, feel free to ask!