<commit_before>#include "joystick.hpp"
// #include "Rotate.h"

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <vector>
#include <string>
#include <math.h>

const int DEAD_ZONE = 16384;
const int AXIS_MAX = 32767;

using namespace ros;
using namespace std;

Joystick joystick;
Publisher pub;

void updateRemote(const TimerEvent&) {
	// get axis values
	// use axis.0 for left/right
	// and axis.1 for up/down
	JoystickEvent event = joystick.getEvent();
	vector<short> axis = event.getAxis();

	// check for button.0 to stop
	vector<bool> buttons = event.getButtons();

	// calculate position values
	double angular = (-1.0) * axis.at(0) / AXIS_MAX;
	double linear  = (-1.0) * axis.at(1) / AXIS_MAX;
	double stick2y = (-1.0) * axis.at(2) / AXIS_MAX;

	angular = min(max(angular, -1.0), 1.0);
	linear = min(max(linear, -1.0), 1.0);
	stick2y = min(max(stick2y, -1.0), 1.0);

	// SPEEED-BUTTON!
	if (!buttons.at(1)) {
		angular *= 0.25;
		linear *= 0.25;
	}
	if (!buttons.at(2)) {
		stick2y *= 0.1; // Scale wheel rotation nice and slow
	}

	if (linear < 0) {
		angular *= (-1.0);
	}

	geometry_msgs::Twist twist;
	twist.angular.z = angular;
	twist.angular.y = stick2y;
	twist.linear.x = linear;

	pub.publish(twist);
}

int main(int argc, char **argv) {
	// init sdl and connect to controller
	SDL_Init(SDL_INIT_JOYSTICK);
	if(!joystick.init()) {
		cout << "Could not find a joystick!\n";
		return 1;
	}
	string name = joystick.getName();
	cout << "Used controller: " << name.c_str() << endl;
	
	// init ros
	init(argc, argv, "remotecontrol");
	NodeHandle n;
	pub = n.advertise<geometry_msgs::Twist>("turtle1/cmd_vel", 1);

	// startup main loop
	Timer remoteTimer = n.createTimer(Duration(0.0166 /*60 Hz*/), updateRemote);
	spin();
	return 0;
}
<commit_msg>remotecontrol: safety measures: lower the maximum motor speed<commit_after>#include "joystick.hpp"
// #include "Rotate.h"

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <vector>
#include <string>
#include <math.h>

const int DEAD_ZONE = 16384;
const int AXIS_MAX = 32767;

using namespace ros;
using namespace std;

Joystick joystick;
Publisher pub;

void updateRemote(const TimerEvent&) {
	// get axis values
	// use axis.0 for left/right
	// and axis.1 for up/down
	JoystickEvent event = joystick.getEvent();
	vector<short> axis = event.getAxis();

	// check for button.0 to stop
	vector<bool> buttons = event.getButtons();

	// calculate position values
	double angular = (-1.0) * axis.at(0) / AXIS_MAX;
	double linear  = (-1.0) * axis.at(1) / AXIS_MAX;
	double stick2y = (-1.0) * axis.at(2) / AXIS_MAX;

	angular = min(max(angular, -1.0), 1.0);
	linear = min(max(linear, -1.0), 1.0);
	stick2y = min(max(stick2y, -1.0), 1.0);

	// SPEEED-BUTTON!
	if (!buttons.at(0)) {
		angular *= 0.25;
		linear *= 0.25;
	} else {
		// Safety measures...
		angular *= 0.75;
		linear *= 0.75;
	}
	if (!buttons.at(1)) {
		stick2y *= 0.2; // Scale wheel rotation nice and slow
	} else {
		stick2y *= 0.5;
	}

	if (linear < 0) {
		angular *= (-1.0);
	}

	geometry_msgs::Twist twist;
	twist.angular.z = angular;
	twist.angular.y = stick2y;
	twist.linear.x = linear;

	pub.publish(twist);
}

int main(int argc, char **argv) {
	// init sdl and connect to controller
	SDL_Init(SDL_INIT_JOYSTICK);
	if(!joystick.init()) {
		cout << "Could not find a joystick!\n";
		return 1;
	}
	string name = joystick.getName();
	cout << "Used controller: " << name.c_str() << endl;
	
	// init ros
	init(argc, argv, "remotecontrol");
	NodeHandle n;
	pub = n.advertise<geometry_msgs::Twist>("turtle1/cmd_vel", 1);

	// startup main loop
	Timer remoteTimer = n.createTimer(Duration(0.0166 /*60 Hz*/), updateRemote);
	spin();
	return 0;
}

{'fraction_non_alphanumeric': 0.16842961757526445, 'fraction_numerical': 0.03661513425549227, 'mean_word_length': 3.5870646766169156, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 19, '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': '5554510', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1436, 'n_words': 361}