/*! @file LegController.h * @brief Common Leg Control Interface and Leg Control Algorithms * * Implements low-level leg control for Mini Cheetah and Cheetah 3 Robots * Abstracts away the difference between the SPIne and the TI Boards (the low level leg control boards) * All quantities are in the "leg frame" which has the same orientation as the * body frame, but is shifted so that 0,0,0 is at the ab/ad pivot (the "hip * frame"). */ #ifndef PROJECT_LEGCONTROLLER_H #define PROJECT_LEGCONTROLLER_H #include "cppTypes.h" #include "leg_control_command_lcmt.hpp" #include "leg_control_data_lcmt.hpp" #include "Dynamics/Quadruped.h" #include "SimUtilities/SpineBoard.h" #include "SimUtilities/ti_boardcontrol.h" /*! * Data sent from the control algorithm to the legs. */ template struct LegControllerCommand { EIGEN_MAKE_ALIGNED_OPERATOR_NEW LegControllerCommand() { zero(); } void zero(); Vec3 tauFeedForward, forceFeedForward, qDes, qdDes, pDes, vDes; Mat3 kpCartesian, kdCartesian, kpJoint, kdJoint; }; /*! * Data returned from the legs to the control code. */ template struct LegControllerData { EIGEN_MAKE_ALIGNED_OPERATOR_NEW LegControllerData() { zero(); } void setQuadruped(Quadruped& quad) { quadruped = &quad; } void zero(); Vec3 q, qd, p, v; Mat3 J; Vec3 tauEstimate; Quadruped* quadruped; }; /*! * Controller for 4 legs of a quadruped. Works for both Mini Cheetah and Cheetah 3 */ template class LegController { public: LegController(Quadruped& quad) : _quadruped(quad) { for (auto& data : datas) data.setQuadruped(_quadruped); } void zeroCommand(); void edampCommand(RobotType robot, T gain); void updateData(const SpiData* spiData); void updateData(const TiBoardData* tiBoardData); void updateCommand(SpiCommand* spiCommand); void updateCommand(TiBoardCommand* tiBoardCommand); void setEnabled(bool enabled) { _legsEnabled = enabled; }; void setLcm(leg_control_data_lcmt* data, leg_control_command_lcmt* command); /*! * Set the maximum torque. This only works on cheetah 3! */ void setMaxTorqueCheetah3(T tau) { _maxTorque = tau; } LegControllerCommand commands[4]; LegControllerData datas[4]; Quadruped& _quadruped; bool _legsEnabled = false; T _maxTorque = 0; bool _zeroEncoders = false; u32 _calibrateEncoders = 0; }; template void computeLegJacobianAndPosition(Quadruped& quad, Vec3& q, Mat3* J, Vec3* p, int leg); #endif // PROJECT_LEGCONTROLLER_H