Cheetah Software  1.0
RobotInterface.h
Go to the documentation of this file.
1 
6 #ifndef PROJECT_ROBOTINTERFACE_H
7 #define PROJECT_ROBOTINTERFACE_H
8 
10 #include <Dynamics/Quadruped.h>
11 #include <Utilities/PeriodicTask.h>
12 #include <cheetah_visualization_lcmt.hpp>
13 #include <condition_variable>
14 #include <lcm-cpp.hpp>
15 #include <mutex>
16 #include <thread>
17 #include "Graphics3D.h"
18 #include "control_parameter_request_lcmt.hpp"
19 #include "control_parameter_respones_lcmt.hpp"
20 #include "gamepad_lcmt.hpp"
21 
22 #define ROBOT_INTERFACE_UPDATE_PERIOD (1.f / 60.f)
23 #define INTERFACE_LCM_NAME "interface"
24 #define TIMES_TO_RESEND_CONTROL_PARAM 5
25 
27  public:
28  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
29 
30  RobotInterface(RobotType robotType, Graphics3D* gfx, PeriodicTaskManager* tm, ControlParameters& userParameters);
32  void startInterface();
33  void stopInterface();
34  void lcmHandler();
35  void sendControlParameter(const std::string& name,
37  ControlParameterValueKind kind, bool isUser);
38 
39  void handleControlParameter(const lcm::ReceiveBuffer* rbuf,
40  const std::string& chan,
41  const control_parameter_respones_lcmt* msg);
42 
43  void handleVisualizationData(const lcm::ReceiveBuffer* rbuf,
44  const std::string& chan,
45  const cheetah_visualization_lcmt* msg);
46 
47  void init() {}
48  void run();
49  void cleanup() {}
50  virtual ~RobotInterface() {
51  delete _simulator;
52  stop();
53  }
54 
55  private:
57  gamepad_lcmt _gamepad_lcmt;
58  control_parameter_request_lcmt _parameter_request_lcmt;
60  lcm::LCM _lcm;
61  uint64_t _robotID;
62  std::thread _lcmThread;
68  bool _running = false;
69 
70  std::mutex _lcmMutex;
71  std::condition_variable _lcmCV;
72  bool _waitingForLcmResponse = false;
73  bool _lcmResponseBad = true;
74 
75  // forward kinematics
80 };
81 
82 #endif // PROJECT_ROBOTINTERFACE_H
RobotType _robotType
FloatingBaseModel< double > _model
void sendControlParameter(const std::string &name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser)
ControlParameterValueKind
EIGEN_MAKE_ALIGNED_OPERATOR_NEW RobotInterface(RobotType robotType, Graphics3D *gfx, PeriodicTaskManager *tm, ControlParameters &userParameters)
Data structure containing parameters for quadruped robot.
Implementation of a periodic function running in a separate thread. Periodic tasks have a task manage...
uint64_t _robotID
FBModelState< double > _fwdKinState
void handleControlParameter(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const control_parameter_respones_lcmt *msg)
PeriodicTaskManager _taskManager
virtual ~RobotInterface()
std::thread _lcmThread
RobotControlParameters & getParams()
Quadruped< double > _quadruped
void handleVisualizationData(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const cheetah_visualization_lcmt *msg)
VisualizationData _visualizationData
control_parameter_request_lcmt _parameter_request_lcmt
Graphics3D * _gfx
DynamicsSimulator< double > * _simulator
bool _pendingControlParameterSend
std::mutex _lcmMutex
bool _waitingForLcmResponse
RobotType
Definition: cppTypes.h:120
std::condition_variable _lcmCV
gamepad_lcmt _gamepad_lcmt
RobotControlParameters _controlParameters
ControlParameters & _userParameters
Visualizer window for simulator.