C++ main entry point

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Back to Robobot B.")
 
Line 1: Line 1:
 
Back to [[Robobot B]].
 
Back to [[Robobot B]].
 +
Back to [[Robobot software description]]
 +
 +
== Main ==
 +
 +
C++ starts executing a function called ''main(int argc, char ** argv)''
 +
 +
In Robobot, this is rather simple and the intention is explained here.
 +
 +
The main.cpp file looks like this (slightly reduced):
 +
 +
/*
 +
#***************************************************************************
 +
#*  Copyright (C) 2023 by DTU
 +
#*  jcan@dtu.dk
 +
#*
 +
#* The MIT License (MIT)  https://mit-license.org/
 +
#***************************************************************************/
 +
// System libraries
 +
#include <iostream>
 +
#include <stdio.h>
 +
#include <string.h>
 +
#include <string>
 +
//
 +
// include local files for data values and functions
 +
#include "uservice.h"
 +
#include "cmixer.h"
 +
#include "sgpiod.h"
 +
#include "bplan20.h"
 +
#include "bplan21.h"
 +
#include "bplan40.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
 +
    if (ini["plan20"]["run"] == "true")
 +
    { // example odometry drive using distance and turned angle
 +
      '''plan20.run'''();
 +
    }
 +
    mixer.setVelocity(0.0);
 +
    mixer.setTurnrate(0.0);
 +
    sleep(1); // to allow robot to stop while logging is running
 +
    // turn off led 16
 +
    gpio.setPin(16, 0);
 +
  }
 +
  // close all logfiles
 +
  service.terminate();
 +
}

Revision as of 09:14, 31 December 2023

Back to Robobot B. Back to Robobot software description

Main

C++ starts executing a function called main(int argc, char ** argv)

In Robobot, this is rather simple and the intention is explained here.

The main.cpp file looks like this (slightly reduced):

/*
#***************************************************************************
#*   Copyright (C) 2023 by DTU
#*   jcan@dtu.dk
#*
#* The MIT License (MIT)  https://mit-license.org/
#***************************************************************************/
// System libraries
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
//
// include local files for data values and functions
#include "uservice.h"
#include "cmixer.h"
#include "sgpiod.h"
#include "bplan20.h"
#include "bplan21.h"
#include "bplan40.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
    if (ini["plan20"]["run"] == "true")
    { // example odometry drive using distance and turned angle
      plan20.run();
    }
    mixer.setVelocity(0.0);
    mixer.setTurnrate(0.0);
    sleep(1); // to allow robot to stop while logging is running
    // turn off led 16
    gpio.setPin(16, 0);
  }
  // close all logfiles
  service.terminate();
}
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox