Projects Robot Simulation 2D Mobile Robot Simulation

2D Mobile Robot Simulation

Introduction

The robot that we have here is a wheeled robot. It has two wheels. It navigates with a differentially steered drive system. If one wheel is rotating faster, the robot will make a curved path. If both wheels are on the same speed, it will make a straight path.

 

 

The Differential Steering System

The differentially steered drive system used in many robots is essentially the same arrangement as that used in a wheelchair. So, most of us have an intuitive grasp of the way it behaves. If both drive wheels turn in tandem, the robot moves in a straight line. If one wheel rotates faster than the other, the robot follows a curved path inward toward the slower wheel. If the wheels turn at equal speed, but in opposite directions, the robot pivots. Thus, steering the robot is just a matter of varying the speeds of the drive wheels

To make it simple, here are the equations used to model differential steering behaviour:

 

 

If the left wheel and the right wheel are at the same  speed, the equation above cannot be implemented since it will result in division by zero error. Using L'Hospital's rule, it can be shown that the equation has limits approaching a straight line.   So, when the left wheel and the right wheel are at the same speed, use this equation:

 

 

The equation for calculating the robot's orientation as a function of wheel velocity and time:

 



Here is the implementation code for those equations:

void CRobot::RobotGo(double *t){
if (canResetTime){
*t = 0;
canResetTime = false;
}

int plusFactor = m_robot.rWheelSpeed + m_robot.lWheelSpeed;
int minusFactor = m_robot.lWheelSpeed - m_robot.rWheelSpeed;

if (m_robot.lWheelSpeed - m_robot.rWheelSpeed != 0.0){
m_robot.theta = m_theta0 + minusFactor * (*t) / m_robot.size ;
m_robot.pos.x = ceil(m_pos0.x + m_robot.size / 2 * plusFactor / minusFactor
* (sin(minusFactor * (*t) / m_robot.size + m_robot.theta0)
- sin(m_robot.theta0)));
m_robot.pos.y = m_pos0.y - m_robot.size / 2 * plusFactor / minusFactor
* (cos(minusFactor * (*t) / m_robot.size + m_robot.theta0)
- cos(m_robot.theta0));
}
else{
m_robot.pos.x = plusFactor / 2 * cos(m_robot.theta) * (*t) + m_pos0.x;
m_robot.pos.y = plusFactor / 2 * sin(m_robot.theta) * (*t) + m_pos0.y;
}
}

A Mobile Robot Simulation

function this.main(this)
this:setspeed(20,20)
while true do
for i = 0, this:getnumberofrobots() - 1 do
this:setactiverobot(i)
a = this:readsensor(1)
b = this:readsensor(5)
if (a - b > 2) then
this:setspeed(7,5)
end

if (a - b < -2) then
this:setspeed(5,7)
end

if( (a - b > -2)  and (a - b < 2) ) then
this:setspeed(5,5)
end
end
this:stepforward()
end

Dim lights Embed Embed this video on your site

Multi-Robot Simulation

--main function
function this.main(this)
this:textline("START...\n")
while(true) do
         for i = 0, this:getnumberofrobots() - 1 do
                  this:setactiverobot(i)
                  front = this:readsensor(0)
                  left = this:readsensor(5)
                  right = this:readsensor(1)

                  if (front < 10) then
                          this:setspeed(4,-4)
                  else
                          delta = 0.5 * (right - left)
                          this:setspeed(4 + delta,4 - delta)
                  end
               end

           this:stepforward()
        end
end

 

Dim lights Embed Embed this video on your site