Skip to content

Commit

Permalink
servo_keyboard_input: Add Windows support (#3290)
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro authored Feb 1, 2025
1 parent 75fb28b commit 2302268
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions moveit_ros/moveit_servo/demos/servo_keyboard_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@
#include <rclcpp/rclcpp.hpp>
#include <signal.h>
#include <stdio.h>
#ifndef WIN32
#include <termios.h>
#include <unistd.h>
#else
#include <conio.h>
#endif

// Define used keys
namespace
Expand Down Expand Up @@ -88,6 +92,7 @@ class KeyboardReader
public:
KeyboardReader() : file_descriptor_(0)
{
#ifndef WIN32
// get the console in raw mode
tcgetattr(file_descriptor_, &cooked_);
struct termios raw;
Expand All @@ -97,23 +102,32 @@ class KeyboardReader
raw.c_cc[VEOL] = 1;
raw.c_cc[VEOF] = 2;
tcsetattr(file_descriptor_, TCSANOW, &raw);
#endif
}
void readOne(char* c)
{
#ifndef WIN32
int rc = read(file_descriptor_, c, 1);
if (rc < 0)
{
throw std::runtime_error("read failed");
}
#else
*c = static_cast<char>(_getch());
#endif
}
void shutdown()
{
#ifndef WIN32
tcsetattr(file_descriptor_, TCSANOW, &cooked_);
#endif
}

private:
int file_descriptor_;
#ifndef WIN32
struct termios cooked_;
#endif
};

// Converts key-presses to Twist or Jog commands for Servo, in lieu of a controller
Expand Down

0 comments on commit 2302268

Please sign in to comment.