#include <HardwareBridge.h>
Definition at line 23 of file HardwareBridge.h.
HardwareBridge::~HardwareBridge |
( |
| ) |
|
|
inline |
void HardwareBridge::handleControlParameter |
( |
const lcm::ReceiveBuffer * |
rbuf, |
|
|
const std::string & |
chan, |
|
|
const control_parameter_request_lcmt * |
msg |
|
) |
| |
Definition at line 92 of file HardwareBridge.cpp.
References _interfaceLCM, ControlParameter::_kind, _parameter_response_lcmt, _robotParams, _userControlParameters, ControlParameters::collection, controlParameterValueKindToString(), controlParameterValueToString(), ControlParameterCollection::lookup(), ControlParameter::set(), SET_ROBOT_PARAM_BY_NAME, and SET_USER_PARAM_BY_NAME.
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");
control_parameter_respones_lcmt _parameter_response_lcmt
ControlParameterCollection collection
ControlParameterValueKind _kind
ControlParameters * _userControlParameters
ControlParameterValueKind
std::string controlParameterValueKindToString(ControlParameterValueKind valueKind)
void set(ControlParameterValue value, ControlParameterValueKind kind)
ControlParameter & lookup(const std::string &name)
std::string controlParameterValueToString(ControlParameterValue v, ControlParameterValueKind kind)
RobotControlParameters _robotParams
void HardwareBridge::handleGamepadLCM |
( |
const lcm::ReceiveBuffer * |
rbuf, |
|
|
const std::string & |
chan, |
|
|
const gamepad_lcmt * |
msg |
|
) |
| |
void HardwareBridge::handleInterfaceLCM |
( |
| ) |
|
void HardwareBridge::initCommon |
( |
| ) |
|
All initialization code that is common between Cheetah 3 and Mini Cheetah
Definition at line 30 of file HardwareBridge.cpp.
References _interfaceLCM, _interfaceLcmThread, handleControlParameter(), handleGamepadLCM(), handleInterfaceLCM(), initError(), prefaultStack(), and setupScheduler().
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");
void handleInterfaceLCM()
void handleControlParameter(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const control_parameter_request_lcmt *msg)
void initError(const char *reason, bool printErrno=false)
std::thread _interfaceLcmThread
void handleGamepadLCM(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const gamepad_lcmt *msg)
void HardwareBridge::initError |
( |
const char * |
reason, |
|
|
bool |
printErrno = false |
|
) |
| |
If an error occurs during initialization, before motors are enabled, print error and exit.
- Parameters
-
reason | Error message string |
printErrno | If true, also print C errno |
Definition at line 17 of file HardwareBridge.cpp.
18 printf(
"FAILED TO INITIALIZE HARDWARE: %s\n", reason);
21 printf(
"Error: %s\n", strerror(errno));
void HardwareBridge::prefaultStack |
( |
| ) |
|
Writes to a 16 KB buffer on the stack. If we are using 4K pages for our stack, this will make sure that we won't have a page fault when the stack grows. Also mlock's all pages associated with the current process, which prevents the cheetah software from being swapped out. If we do run out of memory, the robot program will be killed by the OOM process killer (and leaves a log) instead of just becoming unresponsive.
Definition at line 60 of file HardwareBridge.cpp.
References initError(), and MAX_STACK_SIZE.
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 " void initError(const char *reason, bool printErrno=false)
void HardwareBridge::publishVisualizationLCM |
( |
| ) |
|
void HardwareBridge::run_sbus |
( |
| ) |
|
void HardwareBridge::setupScheduler |
( |
| ) |
|
Configures the
Definition at line 75 of file HardwareBridge.cpp.
References initError(), and TASK_PRIORITY.
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);
void initError(const char *reason, bool printErrno=false)
bool HardwareBridge::_firstRun = true |
|
protected |
lcm::LCM HardwareBridge::_interfaceLCM |
|
protected |
volatile bool HardwareBridge::_interfaceLcmQuit = false |
|
protected |
std::thread HardwareBridge::_interfaceLcmThread |
|
protected |
u64 HardwareBridge::_iterations = 0 |
|
protected |
control_parameter_respones_lcmt HardwareBridge::_parameter_response_lcmt |
|
protected |
int HardwareBridge::_port |
|
protected |
lcm::LCM HardwareBridge::_visualizationLCM |
|
protected |
The documentation for this class was generated from the following files: