Difference between revisions of "Webots"

From RoboWiki
Jump to: navigation, search
(About project)
(Example of source code)
Line 12: Line 12:
  
 
<source lang="cpp">
 
<source lang="cpp">
if (simGetScriptExecutionCount()==0) then
+
  wb_robot_keyboard_enable(TIME_STEP);
    -- This is executed exactly once, the first time this script is executed
+
 
     bubbleRobBase=simGetObjectAssociatedWithScript(sim_handle_self) -- this is bubbleRob's handle
+
  do {
     -- following is the handle of bubbleRob's associated UI (user interface):
+
     sc_update();
     ctrl=simGetUIHandle("bubbleCtrl")
+
      
    -- Set the title of the user interface:
+
     double speeds[2] = {0.0, 0.0};
    simSetUIButtonLabel(ctrl,0,simGetObjectName(bubbleRobBase).." speed")
+
     int c = wb_robot_keyboard_get_key();
     leftMotor=simGetObjectHandle("leftMotor") -- Handle of the left motor
+
     while (c) {
     rightMotor=simGetObjectHandle("rightMotor") -- Handle of the right motor
+
      switch (c) {
    noseSensor=simGetObjectHandle("sensingNose") -- Handle of the proximity sensor
+
        case WB_ROBOT_KEYBOARD_UP:
    minMaxSpeed={50*math.pi/180,300*math.pi/180} -- Min and max speeds for each motor
+
          speeds[LEFT]  += MAX_SPEED;
    backUntilTime=-1 -- Tells whether bubbleRob is in forward or backward mode
+
          speeds[RIGHT] += MAX_SPEED;
end
+
          break;
 
+
        case WB_ROBOT_KEYBOARD_DOWN:
-- if any child script is attached to the bubbleRob tree, this command will execute it/them:
+
          speeds[LEFT]  -= MAX_SPEED;
simHandleChildScript(sim_handle_all_except_explicit)
+
          speeds[RIGHT] -= MAX_SPEED;
-- Retrieve the desired speed from the user interface:  
+
          break;
speed=minMaxSpeed[1]+(minMaxSpeed[2]-minMaxSpeed[1])*simGetUISlider(ctrl,3)/1000
+
        case WB_ROBOT_KEYBOARD_LEFT:
 
+
          speeds[LEFT] -= TURN_SPEED;
result=simReadProximitySensor(noseSensor) -- Read the proximity sensor
+
          speeds[RIGHT] += TURN_SPEED;
-- If we detected something, we set the backward mode:
+
          break;
if (result>0) then backUntilTime=simGetSimulationTime()+4 end
+
        case WB_ROBOT_KEYBOARD_RIGHT:
 
+
          speeds[LEFT]  += TURN_SPEED;
if (backUntilTime<simGetSimulationTime()) then
+
          speeds[RIGHT] -= TURN_SPEED;
     -- When in forward mode, we simply move forward at the desired speed
+
          break;
     simSetJointTargetVelocity(leftMotor,speed)
+
      }
     simSetJointTargetVelocity(rightMotor,speed)
+
      c = wb_robot_keyboard_get_key();
else
+
     }
    -- When in backward mode, we simply backup in a curve at reduced speed
+
     wb_differential_wheels_set_speed(speeds[LEFT], speeds[RIGHT]);
    simSetJointTargetVelocity(leftMotor,-speed/2)
+
      
    simSetJointTargetVelocity(rightMotor,-speed/8)
+
  } while (wb_robot_step(TIME_STEP) != -1);
end
+
 
 
</source>
 
</source>

Revision as of 13:41, 19 June 2012

About project

Webots is a professional robot simulator widely used for educational purposes. The Webots project started in 1996, initially developed by Dr. Olivier Michel at the Swiss Federal Institute of Technology (EPFL) in Lausanne, Switzerland. Webots uses the ODE (Open Dynamics Engine) for detecting of collisions and simulating rigid body dynamics. The ODE library allows one to accurately simulate physical properties of objects such as velocity, inertia and friction. A large collection of freely modifiable robot models comes in the software distribution. In addition, it is also possible to build new models from scratch. When designing a robot model, the user specifies both the graphical and the physical properties of the objects. The graphical properties include the shape, dimensions, position and orientation, colors, and texture of the object. The physical properties include the mass, friction factor, as well as the spring and damping constants. Webots includes a set of sensors and actuators frequently used in robotic experiments, e.g. proximity sensors, light sensors, touch sensors, GPS, accelerometers, cameras, emitters and receivers, servo motors (rotational & linear), position and force sensor, LEDs, grippers, gyros and compass. The robot controller programs can be written in C, C++, Java, Python and MATLAB. The AIBO, Nao and E-puck robot models can also be programmed with the URBI language (URBI license required). Webots offers the possibility to take PNG screen shots and to record the simulations as MPEG (Mac/Linux) and AVI (Windows) movies. Webots worlds are stored in cross-platform .wbt files which format is based on the VRML language. It is also possible to import and export Webots worlds or objects in the VRML format. Another useful feature is that the user can interact with a running simulation at any time, i.e. it possible to move the robots and other object with the mouse. Webots is used in several online robot programming contests. The Robotstadium[1] competition is a simulation of the RoboCup Standard Platform League. In this simulation two teams of Nao play soccer with rules similar to regular soccer. The robots use simulated cameras, ultrasound and pressure sensors. In the Rat's Life[2] competition two simulated e-puck robots compete for energy resources in a Lego maze. Matches are run on a daily basis and the results can be watched in online videos.

Example of source code

  wb_robot_keyboard_enable(TIME_STEP);
  
  do {
    sc_update();
    
    double speeds[2] = {0.0, 0.0};
    int c = wb_robot_keyboard_get_key();
    while (c) {
      switch (c) {
        case WB_ROBOT_KEYBOARD_UP:
          speeds[LEFT]  += MAX_SPEED;
          speeds[RIGHT] += MAX_SPEED;
          break;
        case WB_ROBOT_KEYBOARD_DOWN:
          speeds[LEFT]  -= MAX_SPEED;
          speeds[RIGHT] -= MAX_SPEED;
          break;
        case WB_ROBOT_KEYBOARD_LEFT:
          speeds[LEFT]  -= TURN_SPEED;
          speeds[RIGHT] += TURN_SPEED;
          break;
        case WB_ROBOT_KEYBOARD_RIGHT:
          speeds[LEFT]  += TURN_SPEED;
          speeds[RIGHT] -= TURN_SPEED;
          break;
      }
      c = wb_robot_keyboard_get_key();
    }
    wb_differential_wheels_set_speed(speeds[LEFT], speeds[RIGHT]);
    
  } while (wb_robot_step(TIME_STEP) != -1);