44 #include <std_srvs/Empty.h> 45 #include <kobuki_msgs/MotorPower.h> 46 #include "../include/keyop_core/keyop_core.hpp" 63 accept_incoming(true),
65 wait_for_connection_(true),
66 cmd(new geometry_msgs::Twist()),
67 cmd_stamped(new geometry_msgs::TwistStamped()),
70 angular_vel_step(0.02),
72 quit_requested(false),
73 key_file_descriptor(0)
123 cmd->angular.x = 0.0;
124 cmd->angular.y = 0.0;
125 cmd->angular.z = 0.0;
134 ecl::MilliSleep millisleep;
136 bool connected =
false;
139 if (motor_power_publisher_.getNumSubscribers() > 0)
151 ROS_WARN_STREAM(
"KeyOp: could not connect, trying again after 500ms...");
168 ROS_ERROR(
"KeyOp: check remappings for enable/disable topics).");
172 kobuki_msgs::MotorPower power_cmd;
173 power_cmd.state = kobuki_msgs::MotorPower::ON;
174 motor_power_publisher_.publish(power_cmd);
200 if ((
cmd->linear.x != 0.0) || (
cmd->linear.y != 0.0) || (
cmd->linear.z != 0.0) ||
201 (
cmd->angular.x != 0.0) || (
cmd->angular.y != 0.0) || (
cmd->angular.z != 0.0))
243 raw.c_lflag &= ~(ICANON | ECHO);
249 puts(
"Reading from keyboard");
250 puts(
"---------------------------");
251 puts(
"Forward/back arrows : linear velocity incr/decr.");
252 puts(
"Right/left arrows : angular velocity incr/decr.");
253 puts(
"Spacebar : reset linear/angular velocities.");
254 puts(
"d : disable motors.");
255 puts(
"e : enable motors.");
262 perror(
"read char failed():");
293 case kobuki_msgs::KeyboardInput::KeyCode_Left:
298 case kobuki_msgs::KeyboardInput::KeyCode_Right:
303 case kobuki_msgs::KeyboardInput::KeyCode_Up:
308 case kobuki_msgs::KeyboardInput::KeyCode_Down:
313 case kobuki_msgs::KeyboardInput::KeyCode_Space:
354 cmd->angular.z = 0.0;
360 ROS_INFO(
"KeyOp: die, die, die (disabling power to the device's motor system).");
361 kobuki_msgs::MotorPower power_cmd;
362 power_cmd.state = kobuki_msgs::MotorPower::OFF;
368 ROS_WARN(
"KeyOp: Motor system has already been powered down.");
383 cmd->angular.z = 0.0;
388 ROS_INFO(
"KeyOp: Enabling power to the device subsystem.");
389 kobuki_msgs::MotorPower power_cmd;
390 power_cmd.state = kobuki_msgs::MotorPower::ON;
396 ROS_WARN(
"KeyOp: Device has already been powered up.");
411 ROS_INFO_STREAM(
"KeyOp: linear velocity incremented [" <<
cmd->linear.x <<
"|" <<
cmd->angular.z <<
"]");
430 ROS_INFO_STREAM(
"KeyOp: linear velocity decremented [" <<
cmd->linear.x <<
"|" <<
cmd->angular.z <<
"]");
449 ROS_INFO_STREAM(
"KeyOp: angular velocity incremented [" <<
cmd->linear.x <<
"|" <<
cmd->angular.z <<
"]");
468 ROS_INFO_STREAM(
"KeyOp: angular velocity decremented [" <<
cmd->linear.x <<
"|" <<
cmd->angular.z <<
"]");
480 cmd->angular.z = 0.0;
const std::string & getUnresolvedNamespace() const
void enable()
Reset/re-enable the navigation system.
void disable()
Disables commands to the navigation system.
void publish(const boost::shared_ptr< M > &message) const
bool init()
Initialises the node.
const char * what() const
void decrementLinearVelocity()
If not already minned, decrement the linear velocities..
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Subscriber keyinput_subscriber
geometry_msgs::TwistPtr cmd
ros::Publisher motor_power_publisher_
void remoteKeyInputReceived(const kobuki_msgs::KeyboardInput &key)
Callback function for remote keyboard inputs subscriber.
bool wait_for_connection_
void keyboardInputLoop()
The worker thread function that accepts input keyboard commands.
KeyOpCore()
Default constructor, needs initialisation.
ros::Publisher velocity_publisher_
void incrementLinearVelocity()
If not already maxxed, increment the command velocities..
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void spin()
Worker thread loop; sends current velocity command at a fixed rate.
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
void processKeyboardInput(char c)
Process individual keyboard inputs.
void decrementAngularVelocity()
If not already mined, decrement the angular velocities..
struct termios original_terminal_state
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
void incrementAngularVelocity()
If not already maxxed, increment the angular velocities..
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()