<commit_before>/*
 * Robot.cpp
 *
 *  Created on: Mar 25, 2014
 *      Author: user
 */

#include "Robot.h"

Robot::Robot(char* ip, int port)
{
	_playerClient = new PlayerClient(ip, port);
	_positionProxy = new Position2dProxy(_playerClient);
	_laserProxy = new LaserProxy(_playerClient);
	_laser = new Laser(*_laserProxy, *this);
	_map = new Map();

	init();
}

void Robot::init()
{
	_positionProxy->SetOdometry(0,0,0);
	_positionProxy->SetMotorEnable(true);

	// Workaround to clear sensors
	for (int i = 0; i < 15; i++)
	{
		_playerClient->Read();
	}
}

Robot::~Robot()
{
	delete _laser;
	delete _map;
	delete _positionProxy;
	delete _laserProxy;
	delete _playerClient;
}

double Robot::getX() const
{
	double x = _positionProxy->GetXPos();

	if (DEMO_MODE)
	{
		srand(time(0));
		x += (rand() % DEMO_RANDOM)/DEMO_RANDOM_RATIO;
	}

	return x;
}

double Robot::getY() const
{
	double y = _positionProxy->GetYPos();

	if (DEMO_MODE)
	{
		srand(time(0));
		y += (rand() % DEMO_RANDOM)/DEMO_RANDOM_RATIO;
	}

	return y;
}

double Robot::getYaw() const
{
	double yaw = _positionProxy->GetYaw();

	if (DEMO_MODE)
	{
		srand(time(0));
		yaw += (rand() % DEMO_RANDOM)/DEMO_RANDOM_RATIO;
	}

	return yaw;
}

Map& Robot::getMap() const
{
	return *_map;
}

Laser& Robot::getLaser() const
{
	return *_laser;
}

void Robot::getObstacles(vector<Point>& obstacles) const
{
	_laser->getObstacles(obstacles);
}

bool Robot::canRotate() const
{
	return _laser->canRotate();
}

bool Robot::canMoveForward() const
{
	return _laser->canMoveForward();
}

void Robot::refresh()
{
	// Refresh Sensors buffers
	_playerClient->Read();

	// Handle new Obstacles
	vector<Point> obstacles;
	getObstacles(obstacles);

	Map& map = *_map;
	map.handleObstacles(*this, obstacles);
}

void Robot::setSpeed(double speed, double angularSpeed)
{
	_positionProxy->SetSpeed(speed, angularSpeed);
}
<commit_msg>add funcion to calc rank for each side<commit_after>/*
 * Robot.cpp
 *
 *  Created on: Mar 25, 2014
 *      Author: user
 */

#include "Robot.h"

Robot::Robot(char* ip, int port)
{
	_playerClient = new PlayerClient(ip, port);
	_positionProxy = new Position2dProxy(_playerClient);
	_laserProxy = new LaserProxy(_playerClient);
	_laser = new Laser(*_laserProxy, *this);
	_map = new Map();

	init();
}

void Robot::init()
{
	_positionProxy->SetOdometry(0,0,0);
	_positionProxy->SetMotorEnable(true);

	// Workaround to clear sensors
	for (int i = 0; i < 15; i++)
	{
		_playerClient->Read();
	}
}

Robot::~Robot()
{
	delete _laser;
	delete _map;
	delete _positionProxy;
	delete _laserProxy;
	delete _playerClient;
}

double Robot::getX() const
{
	double x = _positionProxy->GetXPos();

	if (DEMO_MODE)
	{
		srand(time(0));
		x += (rand() % DEMO_RANDOM)/DEMO_RANDOM_RATIO;
	}

	return x;
}

double Robot::getY() const
{
	double y = _positionProxy->GetYPos();

	if (DEMO_MODE)
	{
		srand(time(0));
		y += (rand() % DEMO_RANDOM)/DEMO_RANDOM_RATIO;
	}

	return y;
}

double Robot::getYaw() const
{
	double yaw = _positionProxy->GetYaw();

	if (DEMO_MODE)
	{
		srand(time(0));
		yaw += (rand() % DEMO_RANDOM)/DEMO_RANDOM_RATIO;
	}

	return yaw;
}

Map& Robot::getMap() const
{
	return *_map;
}

Laser& Robot::getLaser() const
{
	return *_laser;
}

void Robot::getObstacles(vector<Point>& obstacles) const
{
	_laser->getObstacles(obstacles);
}

bool Robot::canRotate() const
{
	return _laser->canRotate();
}

bool Robot::canMoveForward() const
{
	return _laser->canMoveForward();
}

void Robot::refresh()
{
	// Refresh Sensors buffers
	_playerClient->Read();

	// Handle new Obstacles
	vector<Point> obstacles;
	getObstacles(obstacles);

	Map& map = *_map;
	map.handleObstacles(*this, obstacles);
}

void Robot::setSpeed(double speed, double angularSpeed)
{
	_positionProxy->SetSpeed(speed, angularSpeed);
}

double Robot::get_right_rank() const
{
	return _laser->GetRightRank();
}

double Robot::get_left_rank() const
{
	return _laser->GetLeftRank();
}

{'fraction_non_alphanumeric': 0.154710237426602, 'fraction_numerical': 0.008169517487873373, 'mean_word_length': 4.711370262390671, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, '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': '3242658', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1579, 'n_words': 319}