<commit_before>/*
* This node subscribes to the topic joy and converts joystick data to real SI velocity commands
* Velocity commands will be published on cmd_vel topic
*/

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>

#define JOY_TIMEOUT_SEC 0.5
#define MAX_TRANSLATION_SPEED 0.5
#define MAX_ROTATION_SPEED 1.57


class TeleopRobotont
{
public:
  TeleopRobotont();

private:
  void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
  void timerCallback(const ros::TimerEvent&);

  ros::NodeHandle nh_;

  ros::Publisher vel_pub_;
  ros::Subscriber joy_sub_;
  ros::Timer timer; 
  ros::Time last_joy_time;

};


TeleopRobotont::TeleopRobotont()
{
  vel_pub_ = nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
  joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 10, &TeleopRobotont::joyCallback, this);
  timer = nh_.createTimer(ros::Duration(0.1), &TeleopRobotont::timerCallback, this);
  last_joy_time = ros::Time::now();
}

void TeleopRobotont::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
  // check the deadman's switch
  if (!joy->buttons[5])
  {
    return; //We have a problem
  }

  last_joy_time = ros::Time::now();

  geometry_msgs::Twist twist;
  twist.linear.x = joy->axes[1]*MAX_TRANSLATION_SPEED;
  twist.linear.y = joy->axes[0]*MAX_TRANSLATION_SPEED;
  twist.angular.z = joy->axes[3]*MAX_ROTATION_SPEED;

  vel_pub_.publish(twist);
  ROS_INFO_STREAM(twist);
}
<commit_msg>changed default joy for XBox One controller; A and B can now be used for changing speed<commit_after>/*
* This node subscribes to the topic joy and converts joystick data to real SI velocity commands
* Velocity commands will be published on cmd_vel topic
*/

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>

#define JOY_TIMEOUT_SEC 0.5
#define MAX_TRANSLATION_SPEED 0.5
#define MAX_ROTATION_SPEED 1.57


class TeleopRobotont
{
public:
  TeleopRobotont();

private:
  void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
  void timerCallback(const ros::TimerEvent&);

  ros::NodeHandle nh_;

  ros::Publisher vel_pub_;
  ros::Subscriber joy_sub_;
  ros::Timer timer; 
  ros::Time last_joy_time;

  double speed = 0.5; // speed multiplier that can be increased/decreased using buttons A and B

};


TeleopRobotont::TeleopRobotont()
{
  vel_pub_ = nh_.advertise<geometry_msgs::Twist>("cmd_vel", 1);
  joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 10, &TeleopRobotont::joyCallback, this);
  timer = nh_.createTimer(ros::Duration(0.1), &TeleopRobotont::timerCallback, this);
  last_joy_time = ros::Time::now();
}

void TeleopRobotont::joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
  // Increase decrease max speed
  if (joy->buttons[0])
  {
    speed-=0.1;
    speed = std::max(speed,0.1);
    ros::Duration(0.5).sleep();
  }
  if (joy->buttons[1])
  {
    speed+=0.1;
    speed = std::min(speed,1.0);
    ros::Duration(0.5).sleep();
  }

  // check the deadman's switch
  if (joy->axes[4] >= 0)
  {
    return; //We have a problem
  }

  last_joy_time = ros::Time::now();

  geometry_msgs::Twist twist;
  twist.linear.x = joy->axes[1]*speed*MAX_TRANSLATION_SPEED;
  twist.linear.y = joy->axes[0]*speed*MAX_TRANSLATION_SPEED;
  twist.angular.z = joy->axes[2]*speed*MAX_ROTATION_SPEED;

  vel_pub_.publish(twist);
  ROS_INFO_STREAM(twist);
}

{'fraction_non_alphanumeric': 0.13929001203369434, 'fraction_numerical': 0.014741275571600482, 'mean_word_length': 4.990990990990991, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1550557', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1237, 'n_words': 255}