Hello there, my name is Legocpp!

An classwork for my robotics class. This was an experimentation on robot steering and obstacle avoidance. My partner and I used Lejos for coding and the Lego Mindstorm unit was provided by our school. Lejos is an Java API we used.


Here is the main robot loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
while(nav.isMoving())
{
	if(Button.ESCAPE.isPressed()) // if we press button to terminate early
	{
		nav.stop();
		return;
	}
 
	boolean crashed = touch.isPressed();
	if(detectObstacle() || crashed)
	{
		Thread.sleep(50); // wait 50ms for sonar update
		if(obstacleAvoid(crashed, error)) // if we avoided the obstacle
		{
			if(goaround()) // if we successfully "gone around"
			{
				nav.goTo(0, 60, true); // continue to goal
				error = 0;
			}
		}
		else error+=2;
	}
}

Disadvantages

We used an dead reckoning behavior to keep track of the current position. Even though it wasn’t as effective, for example: If the robot was stuck and the wheels are moving, then the robot’s position is still updated.

The main goal of our project was to make the robot avoid obstacle. As long as the robot does move behind an obstacle, it is consistent with our goal.

Strengths

The robot was able to decide how far to travel before we should check if we are clear of the obstacle. This was handled by calculating how many times it turned back and found an obstacle is still there.

Video and Blog

You can view the video demonstration and more information on our Robot Design Blog [link].