18 printf(
"FAILED TO INITIALIZE HARDWARE: %s\n", reason);
21 printf(
"Error: %s\n", strerror(errno));
31 printf(
"[HardwareBridge] Init stack\n");
33 printf(
"[HardwareBridge] Init scheduler\n");
36 initError(
"_interfaceLCM failed to initialize\n",
false);
39 printf(
"[HardwareBridge] Subscribe LCM\n");
44 printf(
"[HardwareBridge] Start interface LCM handler\n");
61 printf(
"[Init] Prefault stack...\n");
64 if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
66 "mlockall failed. This is likely because you didn't run robot as " 76 printf(
"[Init] Setup RT Scheduler...\n");
77 struct sched_param params;
79 if (sched_setscheduler(0, SCHED_FIFO, ¶ms) == -1) {
80 initError(
"sched_setscheduler failed.\n",
true);
85 const std::string& chan,
86 const gamepad_lcmt* msg) {
93 const lcm::ReceiveBuffer* rbuf,
const std::string& chan,
94 const control_parameter_request_lcmt* msg) {
100 "[HardwareBridge] Warning: the interface has run a ControlParameter " 101 "iteration, but there is no new request!\n");
107 if (nRequests != 1) {
108 printf(
"[ERROR] Hardware bridge: we've missed %ld requests\n",
112 switch (msg->requestKind) {
115 printf(
"[Warning] Got user param %s, but not using user parameters!\n",
118 std::string name((
char*)msg->name);
122 if ((
s8)param.
_kind != msg->parameterKind) {
123 throw std::runtime_error(
124 "type mismatch for parameter " + name +
", robot thinks it is " +
126 " but received a command to set it to " +
133 memcpy(&v, msg->value,
sizeof(v));
148 printf(
"[User Control Parameter] set %s to %s\n", name.c_str(),
156 std::string name((
char*)msg->name);
160 if ((
s8)param.
_kind != msg->parameterKind) {
161 throw std::runtime_error(
162 "type mismatch for parameter " + name +
", robot thinks it is " +
164 " but received a command to set it to " +
171 memcpy(&v, msg->value,
sizeof(v));
186 printf(
"[Robot Control Parameter] set %s to %s\n", name.c_str(),
194 throw std::runtime_error(
"parameter type unsupported");
220 printf(
"[Hardware Bridge] Waiting for robot parameters...\n");
226 printf(
"[Hardware Bridge] Waiting for user parameters...\n");
231 printf(
"[Hardware Bridge] Got all parameters, starting up!\n");
252 visualizationLCMTask.
start();
276 printf(
"[MiniCheetahHardware] Init vectornav\n");
279 initError(
"failed to initialize vectornav!\n",
false);
299 memcpy(&
_spiData, data,
sizeof(spi_data_t));
301 _spiLcm.publish(
"spi_data", data);
302 _spiLcm.publish(
"spi_command", cmd);
306 cheetah_visualization_lcmt visualization_data;
307 for (
int i = 0; i < 3; i++) {
311 for (
int i = 0; i < 4; i++) {
316 for (
int i = 0; i < 12; i++) {
void handleInterfaceLCM()
control_parameter_respones_lcmt _parameter_response_lcmt
ControlParameterCollection collection
ControlParameterValueKind _kind
ControlParameters * _userControlParameters
void publishVisualizationLCM()
Interface between robot code and robot hardware.
ControlParameterValueKind
GamepadCommand _gamepadCommand
std::string controlParameterValueKindToString(ControlParameterValueKind valueKind)
bool init_vectornav(VectorNavData *vd_data)
VectorNavData * vectorNavData
MiniCheetahHardwareBridge(RobotController *)
bool isFullyInitialized()
volatile bool _interfaceLcmQuit
VisualizationData _visualizationData
void handleControlParameter(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const control_parameter_request_lcmt *msg)
std::string getLcmUrl(s64 ttl)
void set(ControlParameterValue value, ControlParameterValueKind kind)
void sbus_packet_complete()
Function which handles the completion of an SBUS Packet and overrides the LCM control settings as des...
GamepadCommand * driverCommand
CheetahVisualization * cheetahMainVisualization
lcm::LCM _visualizationLCM
int init_sbus(int is_simulator)
ControlParameter & lookup(const std::string &name)
RobotControlParameters * controlParameters
std::string controlParameterValueToString(ControlParameterValue v, ControlParameterValueKind kind)
void set(const gamepad_lcmt *lcmt)
spi_data_t * get_spi_data()
void initError(const char *reason, bool printErrno=false)
std::thread _interfaceLcmThread
PrintTaskStatus statusTask
int receive_sbus(int port)
VectorNavData _vectorNavData
PeriodicTaskManager taskManager
VisualizationData * visualizationData
RobotControlParameters _robotParams
void handleGamepadLCM(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const gamepad_lcmt *msg)
RobotRunner * _robotRunner
spi_command_t * get_spi_command()
CheetahVisualization _mainCheetahVisualization