| 195 | |
| 196 | public: |
| 197 | G1Control(std::string networkInterface) |
| 198 | : time_(0.0), |
| 199 | control_dt_(0.005), |
| 200 | duration_(3.0), |
| 201 | mode_(PR), |
| 202 | mode_machine_(0) { |
| 203 | ChannelFactory::Instance()->Init(0, networkInterface); |
| 204 | |
| 205 | // create publisher |
| 206 | lowcmd_publisher_.reset( |
| 207 | new ChannelPublisher<unitree_hg::msg::dds_::LowCmd_>(HG_CMD_TOPIC)); |
| 208 | lowcmd_publisher_->InitChannel(); |
| 209 | |
| 210 | // create subscriber |
| 211 | lowstate_subscriber_.reset( |
| 212 | new ChannelSubscriber<unitree_hg::msg::dds_::LowState_>( |
| 213 | HG_STATE_TOPIC)); |
| 214 | lowstate_subscriber_->InitChannel( |
| 215 | std::bind(&G1Control::LowStateHandler, this, std::placeholders::_1), 1); |
| 216 | |
| 217 | // create gamepad |
| 218 | joystick_subscriber.reset(new ChannelSubscriber<unitree_go::msg::dds_::WirelessController_>(TOPIC_JOYSTICK)); |
| 219 | joystick_subscriber->InitChannel(std::bind(&G1Control::JoystickHandler, this, std::placeholders::_1), 1); |
| 220 | |
| 221 | |
| 222 | // create threads |
| 223 | command_writer_ptr_ = |
| 224 | CreateRecurrentThreadEx("command_writer", UT_CPU_ID_NONE, 5000, |
| 225 | &G1Control::LowCommandWriter, this); |
| 226 | control_thread_ptr_ = CreateRecurrentThreadEx( |
| 227 | "control", UT_CPU_ID_NONE, 5000, &G1Control::Control, this); |
| 228 | joystick_thread_ptr_ = CreateRecurrentThreadEx( |
| 229 | "nn_ctrl", UT_CPU_ID_NONE, 4000, &G1Control::JoystickStep, this); |
| 230 | |
| 231 | // add lcm subscriber |
| 232 | _simpleLCM.subscribe("pd_plustau_targets", &G1Control::handleActionLCM, this); |
| 233 | _simpleLCM.subscribe("arm_action", &G1Control::handleArmLCM, this); |
| 234 | _simple_LCM_thread = std::thread(&G1Control::_simpleLCMThread, this); |
| 235 | _firstCommandReceived = false; |
| 236 | |
| 237 | // todo: set nominal pose |
| 238 | } |
| 239 | |
| 240 | void JoystickHandler(const void *message) |
| 241 | { |
nothing calls this directly
no test coverage detected