clangtidy corrections part 1
This commit is contained in:
@@ -4,20 +4,24 @@
|
||||
* @brief Contains the implementation of the class TestMode.
|
||||
* @version 0.1
|
||||
* @date 2022-09-08
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "testMode.h"
|
||||
|
||||
void TestMode::run() {
|
||||
if (this->maneuver == Maneuver::Turn) {
|
||||
void TestMode::run()
|
||||
{
|
||||
if (this->maneuver == Maneuver::Turn)
|
||||
{
|
||||
uint16_t delta = abs(this->azimuth - this->getSensorData()->getRealAzimuth());
|
||||
if (delta > this->degree)
|
||||
if (delta > this->degree) {
|
||||
this->abort = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->busy && millis() - this->actionStart > this->maneuverTime || this->abort) {
|
||||
if (this->busy && millis() - this->actionStart > this->maneuverTime || this->abort)
|
||||
{
|
||||
this->busy = false;
|
||||
this->abort = false;
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
@@ -25,62 +29,76 @@ void TestMode::run() {
|
||||
}
|
||||
}
|
||||
|
||||
bool TestMode::drive(int16_t cm, int16_t degree) {
|
||||
if (this->busy)
|
||||
bool TestMode::drive(int16_t cmDistance, int16_t degree)
|
||||
{
|
||||
if (this->busy){
|
||||
return false;
|
||||
}
|
||||
|
||||
this->actionStart = millis();
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Drive);
|
||||
|
||||
if (cm == 0) {
|
||||
//Only left or right
|
||||
if (cmDistance == 0)
|
||||
{
|
||||
// Only left or right
|
||||
this->moveControl->setSpeed(0);
|
||||
|
||||
if (degree < 0)
|
||||
if (degree < 0){
|
||||
this->moveControl->setRotationSpeed(-this->maxSpeeds.rot);
|
||||
else if (degree > 0)
|
||||
}
|
||||
else if (degree > 0){
|
||||
this->moveControl->setRotationSpeed(this->maxSpeeds.rot);
|
||||
|
||||
}
|
||||
|
||||
this->azimuth = this->getSensorData()->getRealAzimuth();
|
||||
this->degree = degree;
|
||||
|
||||
this->maneuverTime = 5 * 1000;
|
||||
this->busy = true;
|
||||
return true;
|
||||
|
||||
} else if (degree == 0) {
|
||||
//Only forward or backward
|
||||
}
|
||||
if (degree == 0)
|
||||
{
|
||||
// Only forward or backward
|
||||
this->moveControl->setRotationSpeed(0);
|
||||
|
||||
if (cm < 0)
|
||||
if (cmDistance < 0){
|
||||
this->moveControl->setSpeed(-this->maxSpeeds.x);
|
||||
else if (cm > 0)
|
||||
}
|
||||
else if (cmDistance > 0){
|
||||
this->moveControl->setSpeed(this->maxSpeeds.x);
|
||||
|
||||
this->maneuverTime = (uint32_t) (((double) abs(cm) / 100.0) / this->maxSpeeds.x) * 1000;
|
||||
}
|
||||
|
||||
this->maneuverTime = static_cast<uint32_t>(((abs(cmDistance) / 100.0) / this->maxSpeeds.x) * 1000);
|
||||
this->busy = true;
|
||||
this->maneuver = Maneuver::Drive;
|
||||
return true;
|
||||
} else {
|
||||
//forward or backward and left or right
|
||||
// TODO: Calculate roationspeed
|
||||
if (cm < 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
// forward or backward and left or right
|
||||
// TODO: Calculate roationspeed
|
||||
if (cmDistance < 0){
|
||||
this->moveControl->setSpeed(-this->maxSpeeds.x);
|
||||
else if (cm > 0)
|
||||
}
|
||||
else if (cmDistance > 0){
|
||||
this->moveControl->setSpeed(this->maxSpeeds.x);
|
||||
|
||||
this->maneuverTime = (uint32_t) (((double) cm / 100.0) / this->maxSpeeds.x) * 1000;
|
||||
}
|
||||
|
||||
this->maneuverTime = static_cast<uint32_t>(((cmDistance / 100.0) / this->maxSpeeds.x) * 1000);
|
||||
this->busy = true;
|
||||
this->maneuver = Maneuver::Drive;
|
||||
return true;
|
||||
}
|
||||
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Stop);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TestMode::leftEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->engineInit(powerPercentage, seconds)) {
|
||||
bool TestMode::leftEngine(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->engineInit(powerPercentage, seconds))
|
||||
{
|
||||
this->moveControl->setRawPowerLeft(powerPercentage);
|
||||
this->maneuver = Maneuver::LeftEngine;
|
||||
std::cout << "TestMode::leftEngine" << std::endl;
|
||||
@@ -89,8 +107,10 @@ bool TestMode::leftEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TestMode::rightEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->engineInit(powerPercentage, seconds)) {
|
||||
bool TestMode::rightEngine(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->engineInit(powerPercentage, seconds))
|
||||
{
|
||||
this->moveControl->setRawPowerRight(powerPercentage);
|
||||
this->maneuver = Maneuver::RightEngine;
|
||||
return true;
|
||||
@@ -98,8 +118,10 @@ bool TestMode::rightEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TestMode::bothEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->engineInit(powerPercentage, seconds)) {
|
||||
bool TestMode::bothEngine(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->engineInit(powerPercentage, seconds))
|
||||
{
|
||||
this->moveControl->setRawPowerLeft(powerPercentage);
|
||||
this->moveControl->setRawPowerRight(powerPercentage);
|
||||
this->maneuver = Maneuver::BothEngine;
|
||||
@@ -108,23 +130,30 @@ bool TestMode::bothEngine(int16_t powerPercentage, int16_t seconds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void TestMode::abortManeuver() {
|
||||
void TestMode::abortManeuver()
|
||||
{
|
||||
this->abort = true;
|
||||
}
|
||||
|
||||
uint8_t TestMode::getRemainingManeuverTime() const {
|
||||
if (this->busy)
|
||||
return (uint8_t) ((this->maneuverTime - (millis() - this->actionStart)) / 1000);
|
||||
uint8_t TestMode::getRemainingManeuverTime() const
|
||||
{
|
||||
if (this->busy){
|
||||
return static_cast<uint8_t>((this->maneuverTime - (millis() - this->actionStart)) / 1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool TestMode::engineInit(int16_t powerPercentage, int16_t seconds) {
|
||||
if (this->busy)
|
||||
bool TestMode::engineInit(int16_t powerPercentage, int16_t seconds)
|
||||
{
|
||||
if (this->busy){
|
||||
return false;
|
||||
if (powerPercentage > 100 || powerPercentage < -100)
|
||||
}
|
||||
if (powerPercentage > TestMode::maxPercentage || powerPercentage < -TestMode::maxPercentage){
|
||||
return false;
|
||||
if (seconds < 0)
|
||||
}
|
||||
if (seconds < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
this->actionStart = millis();
|
||||
this->moveControl->setDrivingStatus(MoveControl::Status::Raw);
|
||||
|
||||
Reference in New Issue
Block a user