a lot of bullshit
This commit is contained in:
+119
-15
@@ -1,47 +1,151 @@
|
||||
/**
|
||||
* @file moveControl.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief Contrains the MoveControl class
|
||||
* @version 0.1
|
||||
* @date 2021-12-14
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
#ifndef MOVE_CONTROL_H
|
||||
#define MOVE_CONTROL_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <PID_v1.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "motorControl.h"
|
||||
#include "speedometer.h"
|
||||
#include "config.h"
|
||||
#include "debugMqtt.h"
|
||||
#include "debugTimes.h"
|
||||
#include "moveControlConfig.h"
|
||||
|
||||
/**
|
||||
* @brief used to set driving status
|
||||
*
|
||||
* When set to stop all motors are set to halt
|
||||
*
|
||||
*/
|
||||
enum DrivingStatus {stop,
|
||||
drive};
|
||||
|
||||
|
||||
/**
|
||||
* @brief This class manages the motors and the encoders
|
||||
*
|
||||
* The controler uses two PIDs to control the motors. The PIDs
|
||||
* use the Speedometer class to get the current speed and the
|
||||
* given target speed to calculate a new duty cycle for the motors.
|
||||
*
|
||||
*/
|
||||
class MoveControl {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Move Control object
|
||||
*
|
||||
* Initalize the motors, encoders and PIDs with given
|
||||
* values in moveControlConfig.h
|
||||
*/
|
||||
MoveControl();
|
||||
void init(MotorControl *left_motor, MotorControl *right_motor,
|
||||
Speedometer *left_encoder, Speedometer *right_encoder);
|
||||
|
||||
/**
|
||||
* @brief Destroy the Move Control object
|
||||
*
|
||||
* Stops the motors with emergencyStop()
|
||||
*/
|
||||
~MoveControl();
|
||||
|
||||
/**
|
||||
* @brief Calls runMoveControl() to update all Values.
|
||||
*
|
||||
* Besides that this function calls the loop() functions for the motors and encodes.
|
||||
* This function should be called every mainloop. If the delay is not reached, than the
|
||||
* functions returns immediately.
|
||||
* @see runMoveControl()
|
||||
* @see setDelay()
|
||||
*/
|
||||
void loop();
|
||||
|
||||
/**
|
||||
* @brief Noramly called repeatedly by loop() to calcluate new values.
|
||||
*/
|
||||
void runMoveControl();
|
||||
|
||||
/**
|
||||
* @brief Set the DrivingStatus
|
||||
*
|
||||
* @see DrDrivingStatus
|
||||
* @param status
|
||||
*/
|
||||
void setDrivingStatus(DrivingStatus status);
|
||||
|
||||
/**
|
||||
* @brief Set the target speed
|
||||
*
|
||||
* If the given speed is close to zero, then the
|
||||
* target speed is set to zero.
|
||||
* @param speed in m/s
|
||||
*/
|
||||
void setSpeed(double speed);
|
||||
|
||||
/**
|
||||
* @brief Set the rotationspeed
|
||||
*
|
||||
* If the given rotationspeed is close to zero, then the
|
||||
* target rotationspeed is set to zero.
|
||||
* @param speed rad/s
|
||||
*/
|
||||
void setRotationspeed(double speed);
|
||||
|
||||
/**
|
||||
* @brief Set the pid tunings
|
||||
*
|
||||
* TODO: check if the function is working or indicates seg fault
|
||||
*
|
||||
* @param side 0 -> left, 1 -> right
|
||||
* @param p
|
||||
* @param i
|
||||
* @param d
|
||||
*/
|
||||
void setPidTunings(uint8_t side, double p, double i, double d);
|
||||
|
||||
private:
|
||||
void calcWheelSpeed();
|
||||
void regulateMotors();
|
||||
void updateWheelSpeed();
|
||||
/**
|
||||
* @brief Set the min delay between each loop
|
||||
*
|
||||
* @param delay time in Milliseconds
|
||||
*/
|
||||
void setDelay(uint8_t delay_) { delay = delay_; }
|
||||
|
||||
DebugMqtt *debug;
|
||||
private:
|
||||
/**
|
||||
* @brief Converts values into wheel speeds
|
||||
*
|
||||
* Converts target speed and target rotationspeed into
|
||||
* wheel speeds
|
||||
*/
|
||||
void calcTargetWheelSpeed();
|
||||
|
||||
/**
|
||||
* @brief Set the target power to motors
|
||||
*
|
||||
* Checks if the driving_status is set to drive.
|
||||
* If yes, then the motors get the pid_out values as targetpower.
|
||||
* If no, then the motors target power is set to zero.
|
||||
*/
|
||||
void regulateMotors();
|
||||
|
||||
/**
|
||||
* @brief Updates the wheel speeds with speedometer
|
||||
*/
|
||||
void updateCurrentWheelSpeed();
|
||||
|
||||
MotorControl *left_motor;
|
||||
MotorControl *right_motor;
|
||||
Speedometer *left_speedometer;
|
||||
Speedometer *right_speedometer;
|
||||
|
||||
DrivingStatus driving_status = DrivingStatus::stop;
|
||||
|
||||
PID *left_pid;
|
||||
PID *right_pid;
|
||||
|
||||
DrivingStatus driving_status = DrivingStatus::stop;
|
||||
|
||||
double x_speed = 0;
|
||||
double rotation_speed = 0;
|
||||
|
||||
@@ -52,6 +156,6 @@ class MoveControl {
|
||||
double left_pid_out;
|
||||
double right_pid_out;
|
||||
|
||||
uint8_t delay = 30;
|
||||
};
|
||||
|
||||
#endif // MOVE_CONTROL_H
|
||||
Reference in New Issue
Block a user