Cheetah Software  1.0
RobotRunner Class Reference

#include <RobotRunner.h>

+ Inheritance diagram for RobotRunner:
+ Collaboration diagram for RobotRunner:

Public Member Functions

EIGEN_MAKE_ALIGNED_OPERATOR_NEW RobotRunner (RobotController *, PeriodicTaskManager *, float, std::string)
 
void init () override
 
void run () override
 
void cleanup () override
 
void initializeStateEstimator (bool cheaterMode=false)
 
virtual ~RobotRunner ()
 
- Public Member Functions inherited from PeriodicTask
 PeriodicTask (PeriodicTaskManager *taskManager, float period, std::string name)
 
void start ()
 
void stop ()
 
void printStatus ()
 
void clearMax ()
 
bool isSlow ()
 
virtual ~PeriodicTask ()
 
float getPeriod ()
 
float getRuntime ()
 
float getMaxPeriod ()
 
float getMaxRuntime ()
 

Public Attributes

RobotController_robot_ctrl
 
GamepadCommanddriverCommand
 
RobotType robotType
 
VectorNavDatavectorNavData
 
CheaterState< double > * cheaterState
 
SpiDataspiData
 
SpiCommandspiCommand
 
TiBoardCommandtiBoardCommand
 
TiBoardDatatiBoardData
 
RobotControlParameterscontrolParameters
 
VisualizationDatavisualizationData
 
CheetahVisualizationcheetahMainVisualization
 

Private Member Functions

void setupStep ()
 
void finalizeStep ()
 

Private Attributes

float _ini_yaw
 
int iter = 0
 
JPosInitializer< float > * _jpos_initializer
 
Quadruped< float > _quadruped
 
LegController< float > * _legController = nullptr
 
StateEstimate< float > _stateEstimate
 
StateEstimatorContainer< float > * _stateEstimator
 
bool _cheaterModeEnabled = false
 
DesiredStateCommand< float > * _desiredStateCommand
 
lcm::LCM _lcm
 
leg_control_command_lcmt leg_control_command_lcm
 
state_estimator_lcmt state_estimator_lcm
 
leg_control_data_lcmt leg_control_data_lcm
 
FloatingBaseModel< float > _model
 
u64 _iterations = 0
 

Detailed Description

Definition at line 30 of file RobotRunner.h.

Constructor & Destructor Documentation

RobotRunner::RobotRunner ( RobotController robot_ctrl,
PeriodicTaskManager manager,
float  period,
std::string  name 
)

Definition at line 15 of file RobotRunner.cpp.

References _robot_ctrl.

17  :
18  PeriodicTask(manager, period, name),
19  _lcm(getLcmUrl(255)) {
20 
21  _robot_ctrl = robot_ctrl;
22 }
PeriodicTask(PeriodicTaskManager *taskManager, float period, std::string name)
std::string getLcmUrl(s64 ttl)
Definition: utilities.cpp:32
lcm::LCM _lcm
Definition: RobotRunner.h:73
RobotController * _robot_ctrl
Definition: RobotRunner.h:44
RobotRunner::~RobotRunner ( )
virtual

Definition at line 189 of file RobotRunner.cpp.

References _jpos_initializer, _legController, and _stateEstimator.

189  {
190  delete _legController;
191  delete _stateEstimator;
192  delete _jpos_initializer;
193 }
LegController< float > * _legController
Definition: RobotRunner.h:68
JPosInitializer< float > * _jpos_initializer
Definition: RobotRunner.h:66
StateEstimatorContainer< float > * _stateEstimator
Definition: RobotRunner.h:70

Member Function Documentation

void RobotRunner::cleanup ( )
overridevirtual

Implements PeriodicTask.

Definition at line 195 of file RobotRunner.cpp.

195 {}
void RobotRunner::finalizeStep ( )
private

Definition at line 158 of file RobotRunner.cpp.

References _iterations, _lcm, _legController, _stateEstimate, CHEETAH_3, leg_control_command_lcm, leg_control_data_lcm, MINI_CHEETAH, robotType, StateEstimate< T >::setLcm(), LegController< T >::setLcm(), spiCommand, state_estimator_lcm, tiBoardCommand, and LegController< T >::updateCommand().

158  {
161  } else if (robotType == RobotType::CHEETAH_3) {
163  } else {
164  assert(false);
165  }
168  _lcm.publish("leg_control_command", &leg_control_command_lcm);
169  _lcm.publish("leg_control_data", &leg_control_data_lcm);
170  _lcm.publish("state_estimator", &state_estimator_lcm);
171  _iterations++;
172 }
SpiCommand * spiCommand
Definition: RobotRunner.h:51
LegController< float > * _legController
Definition: RobotRunner.h:68
leg_control_data_lcmt leg_control_data_lcm
Definition: RobotRunner.h:76
void setLcm(leg_control_data_lcmt *data, leg_control_command_lcmt *command)
TiBoardCommand * tiBoardCommand
Definition: RobotRunner.h:52
void updateCommand(SpiCommand *spiCommand)
StateEstimate< float > _stateEstimate
Definition: RobotRunner.h:69
lcm::LCM _lcm
Definition: RobotRunner.h:73
leg_control_command_lcmt leg_control_command_lcm
Definition: RobotRunner.h:74
void setLcm(state_estimator_lcmt &lcm_data)
u64 _iterations
Definition: RobotRunner.h:80
state_estimator_lcmt state_estimator_lcm
Definition: RobotRunner.h:75
RobotType robotType
Definition: RobotRunner.h:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RobotRunner::init ( )
overridevirtual

Initializes the robot model, state estimator, leg controller, robot data, and any control logic specific data.

Implements PeriodicTask.

Definition at line 28 of file RobotRunner.cpp.

References RobotController::_controlParameters, RobotController::_driverCommand, _jpos_initializer, RobotController::_legController, _legController, RobotController::_model, _model, RobotController::_quadruped, _quadruped, _robot_ctrl, RobotController::_robotType, RobotController::_stateEstimate, _stateEstimate, RobotController::_stateEstimator, _stateEstimator, RobotController::_visualizationData, Quadruped< T >::buildModel(), cheaterState, controlParameters, LegController< T >::datas, driverCommand, RobotController::initializeController(), initializeStateEstimator(), MINI_CHEETAH, robotType, vectorNavData, and visualizationData.

28  {
29  printf("[RobotRunner] initialize\n");
30 
31  // Build the appropriate Quadruped object
33  _quadruped = buildMiniCheetah<float>();
34  } else {
35  _quadruped = buildCheetah3<float>();
36  }
37 
38  // Initialize the model and robot data
41 
42  // Always initialize the leg controller and state entimator
48 
49  // Controller initializations
59 
61 }
LegController< float > * _legController
Definition: RobotRunner.h:68
VisualizationData * _visualizationData
LegController< float > * _legController
VectorNavData * vectorNavData
Definition: RobotRunner.h:48
void initializeStateEstimator(bool cheaterMode=false)
LegControllerData< T > datas[4]
Definition: LegController.h:70
GamepadCommand * driverCommand
Definition: RobotRunner.h:46
StateEstimate< float > * _stateEstimate
RobotControlParameters * controlParameters
Definition: RobotRunner.h:54
GamepadCommand * _driverCommand
RobotControlParameters * _controlParameters
JPosInitializer< float > * _jpos_initializer
Definition: RobotRunner.h:66
CheaterState< double > * cheaterState
Definition: RobotRunner.h:49
StateEstimatorContainer< float > * _stateEstimator
StateEstimate< float > _stateEstimate
Definition: RobotRunner.h:69
FloatingBaseModel< float > * _model
RobotType _robotType
Quadruped< float > _quadruped
Definition: RobotRunner.h:67
FloatingBaseModel< float > _model
Definition: RobotRunner.h:79
virtual void initializeController()=0
StateEstimatorContainer< float > * _stateEstimator
Definition: RobotRunner.h:70
VisualizationData * visualizationData
Definition: RobotRunner.h:55
Quadruped< float > * _quadruped
FloatingBaseModel< T > buildModel()
Definition: Quadruped.cpp:113
RobotController * _robot_ctrl
Definition: RobotRunner.h:44
RobotType robotType
Definition: RobotRunner.h:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RobotRunner::initializeStateEstimator ( bool  cheaterMode = false)

Definition at line 174 of file RobotRunner.cpp.

References _stateEstimator, StateEstimatorContainer< T >::addEstimator(), StateEstimatorContainer< T >::removeAllEstimators(), and StateEstimatorContainer< T >::setContactPhase().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RobotRunner::run ( )
overridevirtual

Runs the overall robot control system by calling each of the major components to run each of their respective steps.

Implements PeriodicTask.

Definition at line 67 of file RobotRunner.cpp.

References _jpos_initializer, _legController, _robot_ctrl, _stateEstimate, _stateEstimator, cheetahMainVisualization, VisualizationData::clear(), LegController< T >::commands, LegController< T >::datas, finalizeStep(), JPosInitializer< T >::IsInitialized(), LegControllerCommand< T >::kdJoint, LegControllerCommand< T >::kpJoint, CheetahVisualization::p, StateEstimate< T >::position, CheetahVisualization::q, LegControllerData< T >::q, StateEstimatorContainer< T >::run(), RobotController::runController(), LegController< T >::setEnabled(), setupStep(), RobotController::updateVisualization(), and visualizationData.

67  {
68  // Run the state estimator step
72 
73  // Update the data from the robot
74  setupStep();
75 
76  static int count_ini(0);
77  ++count_ini;
78  if (count_ini < 10) {
79  _legController->setEnabled(false);
80  } else if (20 < count_ini && count_ini < 30) {
81  _legController->setEnabled(false);
82  } else if (40 < count_ini && count_ini < 50) {
83  _legController->setEnabled(false);
84  } else {
86 
87  // Controller
89  Mat3<float> kpMat;
90  Mat3<float> kdMat;
91  kpMat << 5, 0, 0, 0, 5, 0, 0, 0, 5;
92  kdMat << 0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1;
93 
94  for (int leg = 0; leg < 4; leg++) {
95  _legController->commands[leg].kpJoint = kpMat;
96  _legController->commands[leg].kdJoint = kdMat;
97  }
98  } else {
99  // Run Control
101 
102  // Update Visualization
104  }
105  }
106 
107 
108 
109  // Visualization (will make this into a separate function later)
110  for (int leg = 0; leg < 4; leg++) {
111  for (int joint = 0; joint < 3; joint++) {
112  cheetahMainVisualization->q[leg * 3 + joint] =
113  _legController->datas[leg].q[joint];
114  }
115  }
116  cheetahMainVisualization->p.setZero();
118 
119  // Sets the leg controller commands for the robot appropriate commands
120  finalizeStep();
121 }
void finalizeStep()
bool IsInitialized(LegController< T > *)
LegController< float > * _legController
Definition: RobotRunner.h:68
typename Eigen::Matrix< T, 3, 3 > Mat3
Definition: cppTypes.h:54
LegControllerData< T > datas[4]
Definition: LegController.h:70
virtual void runController()=0
CheetahVisualization * cheetahMainVisualization
Definition: RobotRunner.h:56
void setEnabled(bool enabled)
Definition: LegController.h:61
JPosInitializer< float > * _jpos_initializer
Definition: RobotRunner.h:66
virtual void updateVisualization()=0
void run(CheetahVisualization *visualization=nullptr)
StateEstimate< float > _stateEstimate
Definition: RobotRunner.h:69
void setupStep()
StateEstimatorContainer< float > * _stateEstimator
Definition: RobotRunner.h:70
VisualizationData * visualizationData
Definition: RobotRunner.h:55
RobotController * _robot_ctrl
Definition: RobotRunner.h:44
LegControllerCommand< T > commands[4]
Definition: LegController.h:69

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RobotRunner::setupStep ( )
private

Definition at line 123 of file RobotRunner.cpp.

References _cheaterModeEnabled, _legController, CHEETAH_3, controlParameters, initializeStateEstimator(), MINI_CHEETAH, robotType, LegController< T >::setEnabled(), LegController< T >::setMaxTorqueCheetah3(), spiData, tiBoardData, LegController< T >::updateData(), and LegController< T >::zeroCommand().

123  {
124  // Update the leg data
127  } else if (robotType == RobotType::CHEETAH_3) {
129  } else {
130  assert(false);
131  }
132 
133  // Setup the leg controller for a new iteration
135  _legController->setEnabled(true);
137 
138  // state estimator
139  // check transition to cheater mode:
140  if (!_cheaterModeEnabled && controlParameters->cheater_mode) {
141  printf("[RobotRunner] Transitioning to Cheater Mode...\n");
143  // todo any configuration
144  _cheaterModeEnabled = true;
145  }
146 
147  // check transition from cheater mode:
148  if (_cheaterModeEnabled && !controlParameters->cheater_mode) {
149  printf("[RobotRunner] Transitioning from Cheater Mode...\n");
151  // todo any configuration
152  _cheaterModeEnabled = false;
153  }
154 
155  // todo safety checks, sanity checks, etc...
156 }
TiBoardData * tiBoardData
Definition: RobotRunner.h:53
SpiData * spiData
Definition: RobotRunner.h:50
LegController< float > * _legController
Definition: RobotRunner.h:68
void initializeStateEstimator(bool cheaterMode=false)
void setMaxTorqueCheetah3(T tau)
Definition: LegController.h:67
bool _cheaterModeEnabled
Definition: RobotRunner.h:71
RobotControlParameters * controlParameters
Definition: RobotRunner.h:54
void setEnabled(bool enabled)
Definition: LegController.h:61
void updateData(const SpiData *spiData)
RobotType robotType
Definition: RobotRunner.h:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool RobotRunner::_cheaterModeEnabled = false
private

Definition at line 71 of file RobotRunner.h.

DesiredStateCommand<float>* RobotRunner::_desiredStateCommand
private

Definition at line 72 of file RobotRunner.h.

float RobotRunner::_ini_yaw
private

Definition at line 59 of file RobotRunner.h.

u64 RobotRunner::_iterations = 0
private

Definition at line 80 of file RobotRunner.h.

JPosInitializer<float>* RobotRunner::_jpos_initializer
private

Definition at line 66 of file RobotRunner.h.

lcm::LCM RobotRunner::_lcm
private

Definition at line 73 of file RobotRunner.h.

LegController<float>* RobotRunner::_legController = nullptr
private

Definition at line 68 of file RobotRunner.h.

FloatingBaseModel<float> RobotRunner::_model
private

Definition at line 79 of file RobotRunner.h.

Quadruped<float> RobotRunner::_quadruped
private

Definition at line 67 of file RobotRunner.h.

RobotController* RobotRunner::_robot_ctrl

Definition at line 44 of file RobotRunner.h.

StateEstimate<float> RobotRunner::_stateEstimate
private

Definition at line 69 of file RobotRunner.h.

StateEstimatorContainer<float>* RobotRunner::_stateEstimator
private

Definition at line 70 of file RobotRunner.h.

CheaterState<double>* RobotRunner::cheaterState

Definition at line 49 of file RobotRunner.h.

CheetahVisualization* RobotRunner::cheetahMainVisualization

Definition at line 56 of file RobotRunner.h.

RobotControlParameters* RobotRunner::controlParameters

Definition at line 54 of file RobotRunner.h.

GamepadCommand* RobotRunner::driverCommand

Definition at line 46 of file RobotRunner.h.

int RobotRunner::iter = 0
private

Definition at line 61 of file RobotRunner.h.

leg_control_command_lcmt RobotRunner::leg_control_command_lcm
private

Definition at line 74 of file RobotRunner.h.

leg_control_data_lcmt RobotRunner::leg_control_data_lcm
private

Definition at line 76 of file RobotRunner.h.

RobotType RobotRunner::robotType

Definition at line 47 of file RobotRunner.h.

SpiCommand* RobotRunner::spiCommand

Definition at line 51 of file RobotRunner.h.

SpiData* RobotRunner::spiData

Definition at line 50 of file RobotRunner.h.

state_estimator_lcmt RobotRunner::state_estimator_lcm
private

Definition at line 75 of file RobotRunner.h.

TiBoardCommand* RobotRunner::tiBoardCommand

Definition at line 52 of file RobotRunner.h.

TiBoardData* RobotRunner::tiBoardData

Definition at line 53 of file RobotRunner.h.

VectorNavData* RobotRunner::vectorNavData

Definition at line 48 of file RobotRunner.h.

VisualizationData* RobotRunner::visualizationData

Definition at line 55 of file RobotRunner.h.


The documentation for this class was generated from the following files: