MRC/FullExample: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
Line 12: Line 12:


== Software Executable ==
== Software Executable ==
The software is decomposed into three parts: ''main'', ''Detection'' and ''DriveControl''. The part ''main'' is an implementation of the '''Task Content''' in the Task-Skill-Motion-framework. The '''Skills''' are separated into two parts: those used for detection ('''Detect Wall''') and those for driving ('''Drive Forward''', '''Drive Backward''', '''stop''').
The software is decomposed into three parts: ''main'', ''Detection'' and ''DriveControl''. The part ''main'' is an implementation of the '''Task Content''' in the Task-Skill-Motion-framework. The '''Skills''' are separated into two parts: those used for detection ('''Detect Wall''') and those for driving ('''Drive Forward''', '''Drive Backward''', '''stop''').  
 
To make the decoupling between ''Detection'' and ''DriveControl'' explicitly in the implementation, these are implemented in separate classes.
 
=== Detection ===
The header file of the ''Detection''-class, is shown below. The ''Detection''-class contains a pointer to the io-layer ''inOut'', which contains the latest laser data, ''laser''. The methods contained are ''getSensorData'' and ''wallDetected'', which together describe the '''Detect Wall'''-skill. 
 
<pre>
#ifndef detection_H
#define detection_H
 
#define MIN_DIST_TO_WALL 0.4 // [m]
 
class Detection{
private:
    emc::IO *inOut;
    emc::LaserData laser;
 
public:
    Detection(emc::IO *io){
        inOut = io;
        laser = emc::LaserData();
return;
    }
    bool getSensorData();  // Method to obtain the sensordata
    bool wallDetected();  // Method to check if any wall is in the neighbourhood of the robot
};
 
#endif //detection_H
</pre>
Beneath you will find the ''detection.cpp'', first it includes the structure of the class, described in the header file. In this file, the two method ''getSensorData'' and ''wallDetected'' are described.
 
<pre>
#include "detection.h"
 
    bool Detection::getSensorData() {
        if(inOut->readLaserData(laser)) {
            return true;
        } else {
            return false;
        }
    }
 
    bool Detection::wallDetected() {
        for(int i = 0; i < laser.ranges.size(); ++i) {
            if(laser.ranges[i] < MIN_DIST_TO_WALL) {
                return true;
            }
        }
        return false;
    }
</pre>

Revision as of 11:57, 3 May 2017

Full Example

Task-Skill-Motion

Task-Skill-Motion Framework for Full Example

We would like to create a behavior for Pico, in which:

  • Pico is driving forward, unless a wall is detected.
  • If a wall is detected, PICO drives backwards for x metres,
  • then turns approx. 90 degrees,
  • resumes driving forward.

First, we can describe this behavior in a Task-Skill-Motion Framework, which is shown in the figure, here on the right. This example has no GUI, it does have a user interface, through starting the executable. PICO will then start driving forward, which is selected in the Skill Context. Through monitoring the Detect Wall-skill the Task Monitor might change the skill being active to turn, this is controlled by the task control feedback. As this robot does not store any information about the Environment, the environment context is not present. The Skills control the robot through the Robot Operating System.

Software Executable

The software is decomposed into three parts: main, Detection and DriveControl. The part main is an implementation of the Task Content in the Task-Skill-Motion-framework. The Skills are separated into two parts: those used for detection (Detect Wall) and those for driving (Drive Forward, Drive Backward, stop).

To make the decoupling between Detection and DriveControl explicitly in the implementation, these are implemented in separate classes.

Detection

The header file of the Detection-class, is shown below. The Detection-class contains a pointer to the io-layer inOut, which contains the latest laser data, laser. The methods contained are getSensorData and wallDetected, which together describe the Detect Wall-skill.

#ifndef detection_H
#define detection_H

#define MIN_DIST_TO_WALL 0.4 // [m]

class Detection{
private:
    emc::IO *inOut;
    emc::LaserData laser;

public:
    Detection(emc::IO *io){
        inOut = io;
        laser = emc::LaserData();
	return;
    }
    bool getSensorData();  // Method to obtain the sensordata
    bool wallDetected();   // Method to check if any wall is in the neighbourhood of the robot
};

#endif //detection_H

Beneath you will find the detection.cpp, first it includes the structure of the class, described in the header file. In this file, the two method getSensorData and wallDetected are described.

#include "detection.h"

    bool Detection::getSensorData() {
        if(inOut->readLaserData(laser)) {
            return true;
        } else {
            return false;
        }
    }

    bool Detection::wallDetected() {
        for(int i = 0; i < laser.ranges.size(); ++i) {
            if(laser.ranges[i] < MIN_DIST_TO_WALL) {
                return true;
            }
        }
        return false;
    }