<commit_before>#include "src/engine/d2RobotModel.h"

#include <qrkernel/settingsManager.h>
#include <utils/tracer.h>
#include "constants.h"
//#include "details/tracer.h"
#include "src/engine/physics/realisticPhysicsEngine.h"
#include "src/engine/physics/simplePhysicsEngine.h"
#include "src/engine/worldModel.h"
#include "src/engine/d2ModelWidget.h"
#include "src/engine/timeline.h"
#include "src/engine/worldModel.h"
#include "src/engine/d2ModelTimer.h"

#include <interpreterBase/robotModel/robotParts/motor.h>
#include <interpreterBase/robotModel/robotParts/encoderSensor.h>
#include <interpreterBase/robotModel/robotParts/touchSensor.h>
#include <interpreterBase/robotModel/robotParts/colorSensorBlue.h>
#include <interpreterBase/robotModel/robotParts/colorSensorFull.h>
#include <interpreterBase/robotModel/robotParts/colorSensorGreen.h>
#include <interpreterBase/robotModel/robotParts/colorSensorPassive.h>
#include <interpreterBase/robotModel/robotParts/colorSensorRed.h>

#include <QtCore/QDebug>

using namespace twoDModel;
using namespace twoDModel::physics;
using namespace interpreterBase::robotModel;
using namespace interpreterBase::robotModel::robotParts;

D2RobotModel::D2RobotModel(interpreterBase::robotModel::RobotModelInterface &robotModel
		, Configurer const * const configurer
		, QObject *parent)
	: QObject(parent)
	, mD2ModelWidget(nullptr)
	, mDisplay(configurer->displayWidget(nullptr))
	, mWorldModel(new WorldModel())
	, mPhysicsEngine(nullptr)
	, mTimeline(new Timeline(this))
	, mNoiseGen()
	, mNeedSync(false)
	, mPos(QPointF(0,0))
	, mAngle(0)
	, mRobotModel(robotModel)
	, mConfigurer(configurer)
{
	mNoiseGen.setApproximationLevel(qReal::SettingsManager::value("approximationLevel").toUInt());
	connect(mTimeline, SIGNAL(tick()), this, SLOT(recalculateParams()), Qt::UniqueConnection);
	connect(mTimeline, SIGNAL(nextFrame()), this, SLOT(nextFragment()), Qt::UniqueConnection);
	initPosition();

	createModelWidget();
}

D2RobotModel::~D2RobotModel()
{
	delete mPhysicsEngine;
}

void D2RobotModel::init()
{
}

void D2RobotModel::initPosition()
{
	qDeleteAll(mEngines);
	mEngines.clear();

	for (Device const * const device : mRobotModel.configuration().devices()) {
		if (device->deviceInfo().isA<Motor>()) {
			initEngine(robotWheelDiameterInPx / 2, 0, 0, device->port(), false);
		}
	}

	mBeepTime = 0;
	mPos = mD2ModelWidget ? mD2ModelWidget->robotPos() : QPointF(0, 0);
}

void D2RobotModel::clear()
{
	initPosition();
	mAngle = 0;
	mPos = QPointF(0,0);
}

D2RobotModel::Engine *D2RobotModel::initEngine(int radius, int speed, long unsigned int degrees
		, PortInfo const &port, bool isUsed)
{
	Engine *engine = new Engine();
	engine->radius = radius;
	engine->speed = speed;
	engine->degrees = degrees;
	engine->isUsed = isUsed;
	engine->breakMode = true;
	if (degrees == 0) {
		engine->activeTimeType = DoInf;
	} else {
		engine->activeTimeType = DoByLimit;
	}

	mEngines[port] = engine;

	/// @todo We need some mechanism to set correspondence between motors and encoders. In NXT motors and encoders are
	///       physically plugged into one port, so we can find corresponding port by name. But in TRIK encoders can be
	///       connected differently.
	for (Device const * const device : mRobotModel.configuration().devices()) {
		if (device->deviceInfo().isA<EncoderSensor>() &&
				(device->port().name() == port.name() || device->port().nameAliases().contains(port.name())))
		{
			mMotorToEncoderPortMap[port] = device->port();
			mTurnoverEngines[mMotorToEncoderPortMap[port]] = 0;
		}
	}

	return engine;
}

void D2RobotModel::playSound(int timeInMs)
{
	mBeepTime = qMax(mBeepTime, timeInMs);
}

void D2RobotModel::setNewMotor(int speed, uint degrees, PortInfo const &port, bool breakMode)
{
	mEngines[port]->speed = speed;
	mEngines[port]->degrees = degrees;
	mEngines[port]->isUsed = true;
	mEngines[port]->breakMode = breakMode;
	if (degrees) {
		mEngines[port]->activeTimeType = DoByLimit;
	} else {
		mEngines[port]->activeTimeType = DoInf;
	}
}

int D2RobotModel::varySpeed(int const speed) const
{
	qreal const ran = mNoiseGen.generate(mNoiseGen.approximationLevel(), varySpeedDispersion);
	return truncateToInterval(-100, 100, round(speed * (1 + ran)));
}

void D2RobotModel::countMotorTurnover()<commit_msg>Fixed too quick robot transition when motor power > 100<commit_after>#include "src/engine/d2RobotModel.h"

#include <qrkernel/settingsManager.h>
#include <utils/tracer.h>
#include "constants.h"
//#include "details/tracer.h"
#include "src/engine/physics/realisticPhysicsEngine.h"
#include "src/engine/physics/simplePhysicsEngine.h"
#include "src/engine/worldModel.h"
#include "src/engine/d2ModelWidget.h"
#include "src/engine/timeline.h"
#include "src/engine/worldModel.h"
#include "src/engine/d2ModelTimer.h"

#include <interpreterBase/robotModel/robotParts/motor.h>
#include <interpreterBase/robotModel/robotParts/encoderSensor.h>
#include <interpreterBase/robotModel/robotParts/touchSensor.h>
#include <interpreterBase/robotModel/robotParts/colorSensorBlue.h>
#include <interpreterBase/robotModel/robotParts/colorSensorFull.h>
#include <interpreterBase/robotModel/robotParts/colorSensorGreen.h>
#include <interpreterBase/robotModel/robotParts/colorSensorPassive.h>
#include <interpreterBase/robotModel/robotParts/colorSensorRed.h>

#include <QtCore/QDebug>

using namespace twoDModel;
using namespace twoDModel::physics;
using namespace interpreterBase::robotModel;
using namespace interpreterBase::robotModel::robotParts;

D2RobotModel::D2RobotModel(interpreterBase::robotModel::RobotModelInterface &robotModel
		, Configurer const * const configurer
		, QObject *parent)
	: QObject(parent)
	, mD2ModelWidget(nullptr)
	, mDisplay(configurer->displayWidget(nullptr))
	, mWorldModel(new WorldModel())
	, mPhysicsEngine(nullptr)
	, mTimeline(new Timeline(this))
	, mNoiseGen()
	, mNeedSync(false)
	, mPos(QPointF(0,0))
	, mAngle(0)
	, mRobotModel(robotModel)
	, mConfigurer(configurer)
{
	mNoiseGen.setApproximationLevel(qReal::SettingsManager::value("approximationLevel").toUInt());
	connect(mTimeline, SIGNAL(tick()), this, SLOT(recalculateParams()), Qt::UniqueConnection);
	connect(mTimeline, SIGNAL(nextFrame()), this, SLOT(nextFragment()), Qt::UniqueConnection);
	initPosition();

	createModelWidget();
}

D2RobotModel::~D2RobotModel()
{
	delete mPhysicsEngine;
}

void D2RobotModel::init()
{
}

void D2RobotModel::initPosition()
{
	qDeleteAll(mEngines);
	mEngines.clear();

	for (Device const * const device : mRobotModel.configuration().devices()) {
		if (device->deviceInfo().isA<Motor>()) {
			initEngine(robotWheelDiameterInPx / 2, 0, 0, device->port(), false);
		}
	}

	mBeepTime = 0;
	mPos = mD2ModelWidget ? mD2ModelWidget->robotPos() : QPointF(0, 0);
}

void D2RobotModel::clear()
{
	initPosition();
	mAngle = 0;
	mPos = QPointF(0,0);
}

D2RobotModel::Engine *D2RobotModel::initEngine(int radius, int speed, long unsigned int degrees
		, PortInfo const &port, bool isUsed)
{
	Engine *engine = new Engine();
	engine->radius = radius;
	engine->speed = speed;
	engine->degrees = degrees;
	engine->isUsed = isUsed;
	engine->breakMode = true;
	if (degrees == 0) {
		engine->activeTimeType = DoInf;
	} else {
		engine->activeTimeType = DoByLimit;
	}

	mEngines[port] = engine;

	/// @todo We need some mechanism to set correspondence between motors and encoders. In NXT motors and encoders are
	///       physically plugged into one port, so we can find corresponding port by name. But in TRIK encoders can be
	///       connected differently.
	for (Device const * const device : mRobotModel.configuration().devices()) {
		if (device->deviceInfo().isA<EncoderSensor>() &&
				(device->port().name() == port.name() || device->port().nameAliases().contains(port.name())))
		{
			mMotorToEncoderPortMap[port] = device->port();
			mTurnoverEngines[mMotorToEncoderPortMap[port]] = 0;
		}
	}

	return engine;
}

void D2RobotModel::playSound(int timeInMs)
{
	mBeepTime = qMax(mBeepTime, timeInMs);
}

void D2RobotModel::setNewMotor(int speed, uint degrees, PortInfo const &port, bool breakMode)
{
	mEngines[port]->speed = truncateToInterval(-100, 100, speed);
	mEngines[port]->degrees = degrees;
	mEngines[port]->isUsed = true;
	mEngines[port]->breakMode = breakMode;
	if (degrees) {
		mEngines[port]->activeTimeType = DoByLimit;
	} else {
		mEngines[port]->activeTimeType = DoInf;
	}
}

int D2RobotModel::varySpeed(int const speed) const
{
	qreal const ran = mNoiseGen.generate(mNoiseGen.approximationLevel(), varySpeedDispersion);
	return truncateToInterval(-100, 100, round(speed * (1 + ran)));
}

void D2RobotModel::countMotorTurnover()
{'fraction_non_alphanumeric': 0.13869206644209547, 'fraction_numerical': 0.010338018352886514, 'mean_word_length': 6.121588089330025, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 72, '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': '2498592', 'n_tokens_mistral': 3125, 'n_tokens_neox': 3046, 'n_words': 547}