saved work on cmd timeout, not tested yet

This commit is contained in:
Ruixiang Du
2020-09-14 18:57:27 +08:00
parent 8ba694b894
commit 9e646c78b7
5 changed files with 8 additions and 3 deletions

View File

@@ -107,7 +107,7 @@ void AsyncCAN::SendFrame(const can_frame &frame) {
asio::buffer(&frame, sizeof(frame)),
[](asio::error_code error, size_t bytes_transferred) {
if (error) {
std::cerr << "Failed to send CAN frame";
std::cerr << "Failed to send CAN frame" << std::endl;
}
// std::cout << "frame sent" << std::endl;
});

View File

@@ -17,6 +17,7 @@ namespace westonrobot {
void HunterBase::SendRobotCmd() {
static uint8_t cmd_count = 0;
SendMotionCmd(cmd_count++);
FeedCmdTimeoutWatchdog();
}
void HunterBase::SendMotionCmd(uint8_t count) {

View File

@@ -67,9 +67,12 @@ void MobileBase::StartCmdThread() {
void MobileBase::ControlLoop(int32_t period_ms) {
StopWatch ctrl_sw;
bool print_loop_freq = false;
if (timeout_ms_ < period_ms) timeout_ms_ = period_ms;
uint32_t timeout_iter_num = static_cast<uint32_t>(timeout_ms_ / period_ms);
while (true) {
ctrl_sw.tic();
SendRobotCmd();
if (watchdog_counter_ < timeout_iter_num) SendRobotCmd();
++watchdog_counter_;
ctrl_sw.sleep_until_ms(period_ms);
if (print_loop_freq)
std::cout << "control loop frequency: " << 1.0 / ctrl_sw.toc()

View File

@@ -17,6 +17,7 @@ void ScoutBase::SendRobotCmd() {
static uint8_t cmd_count = 0;
static uint8_t light_cmd_count = 0;
SendMotionCmd(cmd_count++);
FeedCmdTimeoutWatchdog();
if (light_ctrl_requested_) SendLightCmd(light_cmd_count++);
}