www.it-ebooks.info
Part III: Visual Programming Language
Ball Follower
Now you’ll make that all-important transition from line-following to ball-following, and you’ll use vision processing to do it. Robots of the future must be able to see and interpret the world around them. In this project, we’ll show you how to design a VPL diagram that enables a robot to track and follow a ball. Vision-based autonomous navigation is left as an exercise for you.
Like the previous project, you’ll implement a Simulation Environment conducive to ball-following, along with any needed services, and then implement a VPL diagram to orchestrate the behavior of the robot.
Building the Simulation Environment
In this project, you use a service to initialize the Simulation Environment. You can find the source code in Chapter12\BallCourt. This service is fairly simple. The PopulateWorld method in the BallCourt.cs file does the usual work of creating sky and ground entities. In this case, the “ground” is a slab rather than an infinite plane but it has essentially the same function.
The BuildArena method builds a ball court with four walls as follows:
MaterialProperties bouncyMaterial =
new MaterialProperties(“Bouncy”, 1.0f, 0.5f, 0.6f); BoxShape[] boxShapes = new BoxShape[]
{
new BoxShape(new BoxShapeProperties(0,
new Pose(new Vector3(0, 0.5f*_state.Scale, -4*_state.Scale)),
new Vector3(12*_state.Scale, 1*_state.Scale, 0.25f*_state.Scale))), new BoxShape(new BoxShapeProperties(0,
new Pose(new Vector3(0, 0.5f*_state.Scale, 4*_state.Scale)),
new Vector3(12*_state.Scale, 1*_state.Scale, 0.25f*_state.Scale))), new BoxShape(new BoxShapeProperties(0,
new Pose(new Vector3(-(6f - 0.125f)*_state.Scale, 0.5f*_state.Scale, 0)), new Vector3(0.25f*_state.Scale, 1*_state.Scale, 8f*_state.Scale))),
new BoxShape(new BoxShapeProperties(0,
new Pose(new Vector3( (6f - 0.125f)*_state.Scale, 0.5f*_state.Scale, 0)), new Vector3(0.25f*_state.Scale, 1*_state.Scale, 8f*_state.Scale))),
};
boxShapes[0].State.Material = bouncyMaterial; boxShapes[1].State.Material = bouncyMaterial; boxShapes[2].State.Material = bouncyMaterial; boxShapes[3].State.Material = bouncyMaterial;
MultiShapeEntity arena = new MultiShapeEntity(boxShapes, null); arena.State.Name = “BallCourt”; arena.State.Assets.DefaultTexture = “BrickWall.dds”; SimulationEngine.GlobalInstancePort.Insert(arena);
Notice that a new material called Bouncy is defined with a restitution set to 1.0f. We also make the walls bouncy so that the ball continues to bounce from wall to wall within the court, enabling our robot to follow it. Each of the walls is defined with a size that can be scaled with the _state.Scale variable.
A MultiShapeEntity is created to hold the wall shapes and then inserted into the Simulation Environment.