本文整理汇总了C++中MessageHandler::flush方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageHandler::flush方法的具体用法?C++ MessageHandler::flush怎么用?C++ MessageHandler::flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHandler
的用法示例。
在下文中一共展示了MessageHandler::flush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
unsigned int packet_miss_counter = 0;
for (cycle_number = 0; exit_flag == false; cycle_number++) {
robotinterface_read_state_blocking();
control_time = get_time() - init_time;
/// Pack and send a servo status
servo_packet.header.protocol_id = 0x00;
servo_packet.header.cycle_number = cycle_number;
robotinterface_get_actual(servo_packet.position, servo_packet.velocity);
write (fd_udp_send, (void *) &servo_packet, sizeof(ServoPacket));
/// Try to receive a command packet within 7ms
fd_set read_fds;
struct timeval timeout;
FD_ZERO(&read_fds);
FD_SET(fd_udp_recv, &read_fds);
timeout.tv_sec = 0;
timeout.tv_usec = 3000;
if (select(fd_udp_recv+1, &read_fds, NULL, NULL, &timeout) < 0) {
cout << "Error in select for receiving. Shutting down." << endl;
stop_robot();
break;
}
/// Test and handle, if data is waiting
if (FD_ISSET(fd_udp_recv, &read_fds)) {
/// Got a valid packet in time. Clear the missed package counter
packet_miss_counter = 0;
/// Get data from external controller
read_size = read (fd_udp_recv, recv_buffer, 1024);
/// Guard against wrong packet sizes
if (read_size != sizeof(PPacket) && read_size != sizeof(PVAPacket)){
cout << "error in packet: size=" << read_size <<endl;
stop_robot();
break;
}
/// Read into a PVAPacket
memcpy((void *) &pva_packet, (void *) recv_buffer, read_size);
/// Warn on wrong cycle number
if (pva_packet.header.cycle_number != cycle_number) {
cout << "Warning!!!! Sequence error" << endl;
}
/// Extrapolate velocities and accelerations, if a pure position packet was received
if (read_size == sizeof(PPacket)){
for(j=0; j<6;j++){
pva_packet.velocity[j] = (pva_packet.position[j] - last_pva_packet.position[j])/0.008;
pva_packet.acceleration[j] = (pva_packet.velocity[j] - last_pva_packet.velocity[j])/0.008;
}
}
/// Send the new pva command
robotinterface_command_position_velocity_acceleration(pva_packet.position,
pva_packet.velocity,
pva_packet.acceleration);
} else {
/// The select must have timed out, and no packet is received.
/// Test and increase the missed packet counter
if(packet_miss_counter >= MAX_PACKET_MISS){
/// Must drop out
if (cycle_number%125 == 0){
cout << "!!! Resting due to too many packet misses !!!" << endl;
}
robotinterface_command_velocity(zero_vector);
//stop_robot();
} else {
packet_miss_counter++;
cout << "!!! Warning !!! : Missed packet deadline (count " << packet_miss_counter << "). Continuing with strategy: ";
/// Strategy: Maintain current velocity, with zero acceleration
cout << "Maintained velocity."<<endl;
for(j=0; j<6; j++){
pva_packet.position[j] += 0.008 * pva_packet.velocity[j];
pva_packet.acceleration[j] = 0.0;
}
/// Strategy: Just command zero velocity.
//cout << "Maintained velocity."<<endl;
//robotinterface_command_velocity(zero_vector);
/// Send the synthetic command.
robotinterface_command_position_velocity_acceleration(pva_packet.position,
pva_packet.velocity,
pva_packet.acceleration);
}
}
// Commit changes
robotinterface_send();
/// Save pva data for extrapolation
memcpy((void *) &last_pva_packet, (void *) &pva_packet, sizeof(PVAPacket));
// Flush messages to stdout
msg_handler.flush();
}
cout << "- Speeding down" <<endl;
for (j = 0; j < 10; j++) {
robotinterface_read_state_blocking();
robotinterface_command_velocity(zero_vector);
robotinterface_send();
}
cout << "- Closing" << endl;
robotinterface_close();
cout << "Done." << endl;
return 0;
}