Robobot new behaviour plan

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(Add to CMakeLists.txt)
 
(7 intermediate revisions by one user not shown)
Line 15: Line 15:
 
Then add the new plan to the repository (if a repository is used)
 
Then add the new plan to the repository (if a repository is used)
  
==== Rename class name ====
+
==== Rename ====
  
A number of variables and types need to be renamed.
+
Several variables and types need to be renamed.
  
 
===== Header file =====
 
===== Header file =====
  
* Search and replace 'BPlan20' to 'BPlan100'  (three places)
+
* Search and replace 'BPlan20' with 'BPlan100'  (three places)
* rename 'plan20' (last line) to 'plan100'
+
* Rename 'plan20' (last line) to 'plan100'
  
The bplan100.h should be changes to look like:
+
The bplan100.h should be changed to look like this:
 
  class BPlan100
 
  class BPlan100
 
  {
 
  {
Line 42: Line 42:
 
* Change all "Plan20" to "Plan100" - used in comments and debug print.
 
* Change all "Plan20" to "Plan100" - used in comments and debug print.
  
Parts of the old file looks like:
+
Parts of the new file could look like this:
  
  #include "bplan20.h"
+
...
  BPlan20 plan20;
+
  #include "bplan100.h"
 +
   
 +
// create class object
 +
BPlan100 plan100;
 
   
 
   
  void BPlan20::setup()
+
  void BPlan100::setup()
 
  { // ensure there is default values in ini-file
 
  { // ensure there is default values in ini-file
  if (not ini["plan20"].has("log"))
+
  if (not ini["plan100"].has("log"))
  { // no data yet, so generate some default values
+
  { // no data yet, so generate some default values
    ini["plan20"]["log"] = "true";
+
    ini["plan100"]["log"] = "true";
    ini["plan20"]["run"] = "false";
+
    ini["plan100"]["run"] = "false";
 +
...
 +
 
 +
==== Main.cpp ====
 +
 
 +
Include the new plan in the main.cpp function
 +
 
 +
The main.cpp gives the execution order, so include the definition and add this new plan to the right place, like:
 +
 
 +
$ cd ~/svn/robobot/raubase/src
 +
$ nano main.cpp
 +
...
 +
#include "bplan21.h"
 +
#include "bplan40.h"
 +
'''#include "bplan100.h"'''
 +
 +
int main (int argc, char **argv)
 +
{ // prepare all modules and start data flow
 +
  bool setupOK = service.setup(argc, argv);
 +
  if (setupOK)
 +
  { // turn on LED on port 16
 +
    gpio.setPin(16, 1);
 +
    // run the planned missions
 +
    '''plan100.run();'''
 +
    plan20.run();
 +
    plan21.run();
 +
    plan40.run();
 +
    //
 +
    mixer.setVelocity(0.0);
 +
    ...
 +
 
 +
==== Change the plan ====
 +
 
 +
Change the BPlan100::run() function as appropriate
 +
 
 +
...
 +
void BPlan100::run()
 +
{
 +
  if (not setupDone)
 +
    setup();
 +
  if (ini["plan100"]["run"] == "false")
 +
    return;
 +
  //
 +
  UTime t("now");
 +
  bool finished = false;
 +
  bool lost = false;
 +
  state = 10;
 +
  oldstate = state;
 +
  //
 +
  toLog("Plan100 started");
 +
  //
 +
  while (not finished and not lost and not service.stop)
 +
  {
 +
    switch (state)
 +
    { // next challenge
 +
      case 10:
 +
        toLog("Reset pose");
 +
...
  
 
==== Add to CMakeLists.txt ====
 
==== Add to CMakeLists.txt ====
Line 58: Line 118:
 
Add the new cpp file to the CMakeLists.txt to the list of files, like
 
Add the new cpp file to the CMakeLists.txt to the list of files, like
  
  $ nano ../CMakeLists.txt
+
  $ cd ~/svn/robobot/raubase
 +
$ nano CMakeLists.txt
 
  ...
 
  ...
 
  add_executable(raubase
 
  add_executable(raubase
Line 70: Line 131:
  
  
(hertil)
+
==== Compile ====
 +
 
 +
Then, compile and test.
 +
 
 +
$ cd ~/svn/robobot/raubase/build
 +
$ make
 +
[  3%] Building CXX object CMakeFiles/raubase.dir/src/bplan100.cpp.o
 +
[  7%] Building CXX object CMakeFiles/raubase.dir/src/main.cpp.o
 +
[ 11%] Linking CXX executable raubase
 +
[100%] Built target raubase

Latest revision as of 08:58, 20 January 2024

Back to Robobot

Back to Robobot software description

Contents

[edit] Create a new behaviour plan

[edit] Copy from existing plan

The easy way is to copy an existing plan, e.g.:

$ cd ~/svn/robobot/raubase/src
$ cp bplan20.cpp bplan100.cpp
$ cp bplan20.h bplan100.h

Then add the new plan to the repository (if a repository is used)

[edit] Rename

Several variables and types need to be renamed.

[edit] Header file
  • Search and replace 'BPlan20' with 'BPlan100' (three places)
  • Rename 'plan20' (last line) to 'plan100'

The bplan100.h should be changed to look like this:

class BPlan100
{
public:
    ~BPlan100();
  void setup();
  void run();
  ...
};
extern BPlan100 plan100;
[edit] Cpp file
  • Change the includefile "bplan20.h" to "bplan100.h"
  • Rename 'BPlan20' to 'BPlan100'
  • Change all "plan20" to "plan100" to name the new class, make a new section in the configuration file, and change the name of the logfile.
  • Change all "Plan20" to "Plan100" - used in comments and debug print.

Parts of the new file could look like this:

...
#include "bplan100.h"

// create class object
BPlan100 plan100;

void BPlan100::setup()
{ // ensure there is default values in ini-file
 if (not ini["plan100"].has("log"))
 { // no data yet, so generate some default values
   ini["plan100"]["log"] = "true";
   ini["plan100"]["run"] = "false";
...

[edit] Main.cpp

Include the new plan in the main.cpp function

The main.cpp gives the execution order, so include the definition and add this new plan to the right place, like:

$ cd ~/svn/robobot/raubase/src
$ nano main.cpp
...
#include "bplan21.h"
#include "bplan40.h"
#include "bplan100.h"

int main (int argc, char **argv)
{ // prepare all modules and start data flow
  bool setupOK = service.setup(argc, argv);
  if (setupOK)
  { // turn on LED on port 16
    gpio.setPin(16, 1);
    // run the planned missions
    plan100.run();
    plan20.run();
    plan21.run();
    plan40.run();
    //
    mixer.setVelocity(0.0);
    ...

[edit] Change the plan

Change the BPlan100::run() function as appropriate

...
void BPlan100::run()
{
 if (not setupDone)
   setup();
 if (ini["plan100"]["run"] == "false")
   return;
 //
 UTime t("now");
 bool finished = false;
 bool lost = false;
 state = 10;
 oldstate = state;
 //
 toLog("Plan100 started");
 //
 while (not finished and not lost and not service.stop)
 {
   switch (state)
   { // next challenge
     case 10:
       toLog("Reset pose");
...

[edit] Add to CMakeLists.txt

Add the new cpp file to the CMakeLists.txt to the list of files, like

$ cd ~/svn/robobot/raubase
$ nano CMakeLists.txt
...
add_executable(raubase
     src/bplan20.cpp
     src/bplan21.cpp
     src/bplan40.cpp
     src/bplan100.cpp
     src/cedge.cpp
     src/cheading.cpp
...


[edit] Compile

Then, compile and test.

$ cd ~/svn/robobot/raubase/build
$ make
[  3%] Building CXX object CMakeFiles/raubase.dir/src/bplan100.cpp.o
[  7%] Building CXX object CMakeFiles/raubase.dir/src/main.cpp.o
[ 11%] Linking CXX executable raubase
[100%] Built target raubase
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox