Cheetah Software  1.0
main_helper.cpp
Go to the documentation of this file.
1 
9 #include <HardwareBridge.h>
10 #include "SimulationBridge.h"
11 
12 #include <main_helper.h>
13 #include <cassert>
14 #include <iostream>
15 
16 #include <RobotController.h>
18 
20 
24 void printUsage() {
25  printf(
26  "Usage: robot [robot-id] [sim-or-robot]\n\twhere robot-id: 3 for "
27  "cheetah 3, m for mini-cheetah\n\t sim-or-robot: s for sim, r for "
28  "robot\n");
29 }
30 
31 int main_helper(int argc, char** argv, RobotController* ctrl) {
33  if (argc != 3) {
34  printUsage();
35  return EXIT_FAILURE;
36  }
37 
38  if (argv[1][0] == '3') {
39  gMasterConfig._robot = RobotType::CHEETAH_3;
40  } else if (argv[1][0] == 'm') {
41  gMasterConfig._robot = RobotType::MINI_CHEETAH;
42  } else {
43  printUsage();
44  return EXIT_FAILURE;
45  }
46 
47  if (argv[2][0] == 's') {
48  gMasterConfig.simulated = true;
49  } else if (argv[2][0] == 'r') {
50  gMasterConfig.simulated = false;
51  } else {
52  printUsage();
53  return EXIT_FAILURE;
54  }
55 
56  printf("[Quadruped] Cheetah Software\n");
57  printf(" Quadruped: %s\n",
58  gMasterConfig._robot == RobotType::MINI_CHEETAH ? "Mini Cheetah"
59  : "Cheetah 3");
60  printf(" Driver: %s\n", gMasterConfig.simulated
61  ? "Development Simulation Driver"
62  : "Quadruped Driver");
63 
64  // dispatch the appropriate driver
65  if (gMasterConfig.simulated) {
66  if (gMasterConfig._robot == RobotType::MINI_CHEETAH) {
67  SimulationBridge simulationBridge(gMasterConfig._robot, ctrl);
68  simulationBridge.run();
69  printf("[Quadruped] SimDriver run() has finished!\n");
70  } else if (gMasterConfig._robot == RobotType::CHEETAH_3) {
71  SimulationBridge simulationBridge(gMasterConfig._robot, ctrl);
72  simulationBridge.run();
73  } else {
74  printf("[ERROR] unknown robot\n");
75  assert(false);
76  }
77  } else {
78  if (gMasterConfig._robot == RobotType::MINI_CHEETAH) {
80  hw.run();
81  printf("[Quadruped] SimDriver run() has finished!\n");
82  } else if (gMasterConfig._robot == RobotType::CHEETAH_3) {
83  printf("[ERROR] can't do cheetah 3 hardware\n");
84  assert(false);
85  } else {
86  printf("[ERROR] unknown robot\n");
87  assert(false);
88  }
89  }
90 
91  return 0;
92 }
bool simulated
Definition: Types.h:8
Interface between robot code and robot hardware.
void printUsage()
Definition: main_helper.cpp:24
MasterConfig gMasterConfig
Definition: main_helper.cpp:19
RobotType _robot
Definition: Types.h:7
void install_segfault_handler()
int main_helper(int argc, char **argv, RobotController *ctrl)
Definition: main_helper.cpp:31