a lot of bullshit
This commit is contained in:
+2
-128
@@ -1,136 +1,10 @@
|
||||
// Global config file
|
||||
// The front is where the boards are
|
||||
|
||||
|
||||
//Pin config
|
||||
//Left
|
||||
#define M_DIR_11 27
|
||||
#define M_DIR_12 12
|
||||
#define M_PWM_1 13
|
||||
#define M_ENCODE_1A 33
|
||||
#define M_ENCODE_1B 32
|
||||
//Right
|
||||
#define M_DIR_21 23
|
||||
#define M_DIR_22 14
|
||||
#define M_PWM_2 22
|
||||
#define M_ENCODE_2A 26
|
||||
#define M_ENCODE_2B 25
|
||||
//GPS
|
||||
//GPS Serial Pins
|
||||
#define GPS_RX 16
|
||||
#define GPS_TX 17
|
||||
#define GPS_BAUD 9600
|
||||
|
||||
//Motors
|
||||
#define LEFT_MOTOR 1
|
||||
#define RIGHT_MOTOR 2
|
||||
#define BOTH_MOTOR 3
|
||||
|
||||
//Directions
|
||||
#define STOP 0
|
||||
#define FORWARD 1
|
||||
#define BACKWARD 2
|
||||
|
||||
//MotorControl config
|
||||
#define RUN_MOTOR_CONTROL_DELAY 10 // Normal 10
|
||||
#define PWM_FREQ 16000
|
||||
#define PWM_RES 8
|
||||
#define PWM_CHANNEL_M1 0
|
||||
#define PWM_CHANNEL_M2 1
|
||||
#define POWER_STEPS 2 // A total of 20 levels ( 100 / SPEED_STEPS ) * RUN_MOTOR_CONTROL_DELAY = 500ms
|
||||
#define PWM_MIN 120
|
||||
#define PWM_MAX 245 // Max 98% of 2^PWM_RES
|
||||
|
||||
//Speedometer config
|
||||
#define RUN_SPEEDOMETER_DELAY 30 // Normal 30 untested
|
||||
#define ENC_FILTER 1023 // 1023 is max
|
||||
#define ENC_STEPS 1024
|
||||
#define WHEEL_DIAMETER 0.1263 //meter
|
||||
#define BUF_SIZE 10
|
||||
|
||||
//MoveControl config
|
||||
#define RUN_MOVE_CONTROL_DELAY 10
|
||||
#define ACCELERATE_STEPS 1
|
||||
#define PID_LEFT_P 85
|
||||
#define PID_LEFT_I 0
|
||||
#define PID_LEFT_D 0
|
||||
#define PID_RIGHT_P 75
|
||||
#define PID_RIGHT_I 0
|
||||
#define PID_RIGHT_D 0
|
||||
#define PID_OUT_MIN -100
|
||||
#define PID_OUT_MAX 100
|
||||
#define PID_SAMPLETIME 30
|
||||
|
||||
//ManualControl config
|
||||
#define RUN_MANUALCONTROL_DELAY 10 // normaly 10
|
||||
#define MANUALCONTROL_MAX_SPEED 1.0 // m/s
|
||||
#define MANUALCONTROL_MAX_ROTATION 7.0 // rad/s
|
||||
|
||||
//MQTT global config
|
||||
#define MQTT_BUFFER_SITE 128
|
||||
#define MQTT_TIME_RECONNECT 2500
|
||||
|
||||
// PS3 Controller
|
||||
// ESP32 MAC BL 24:62:AB:F2:4B:3A
|
||||
|
||||
#define RHEDE
|
||||
|
||||
//Network config RHEDE
|
||||
#ifdef RHEDE
|
||||
#define WLAN_SSID "LebennigHuus"
|
||||
#define WLAN_PASSWORD "Punica-699"
|
||||
#define WLAN_IP 0x040BA8C0 //192.168.11.4
|
||||
#define WLAN_SUBNETMASK 0x0080FFFF //255.255.128.0
|
||||
#define WLAN_GATEWAY 0x0100a8c0 //192.168.0.1
|
||||
#define MQTT_SERVER 0x0701A8C0 //192.168.1.7
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_AUTH
|
||||
#define MQTT_USER "kleiax"
|
||||
#define MQTT_PASSWORD "p?{$_~5%hBM7wrcFkr55KWr#"
|
||||
#define NTP_SERVER 0x0100a8c0 //192.168.0.1
|
||||
#endif //RHEDE
|
||||
|
||||
|
||||
//Network config HW1
|
||||
#ifdef HW1
|
||||
#define WLAN_SSID "hw1_gast"
|
||||
#define WLAN_PASSWORD "KeineAhnung"
|
||||
#define WLAN_IP 0x3400a8c0 //192.168.0.67
|
||||
#define WLAN_SUBNETMASK 0x00FFFFFF //255.255.255.0
|
||||
#define WLAN_GATEWAY 0x0100a8c0 //192.168.0.1
|
||||
#define MQTT_SERVER 0xD84016AC // 172.22.64.216
|
||||
#define MQTT_PORT 1883
|
||||
#define NTP_SERVER "2.de.pool.ntp.org"
|
||||
#endif //HW1
|
||||
|
||||
//Network config FRENZY
|
||||
#ifdef FRENZY
|
||||
#define WLAN_SSID "GNX7EDD84-2"
|
||||
#define WLAN_PASSWORD "2W2ZLPJ9NVQ3"
|
||||
#define WLAN_IP 0x0F01a8c0 //192.168.1.15
|
||||
#define WLAN_SUBNETMASK 0x00FFFFFF //255.255.255.0
|
||||
#define WLAN_GATEWAY 0xfe01a8c0 //192.168.1.254
|
||||
#define MQTT_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#define MQTT_PORT 1883
|
||||
#define NTP_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#endif //FRENZY
|
||||
|
||||
//Network config TPMOBIL
|
||||
#ifdef TPMOBIL
|
||||
#define WLAN_SSID "TP-Mobil"
|
||||
#define WLAN_PASSWORD "Punica-699"
|
||||
#define WLAN_IP 0x0F01a8c0 //192.168.1.15
|
||||
#define WLAN_SUBNETMASK 0x00FFFFFF //255.255.255.0
|
||||
#define WLAN_GATEWAY 0x0101a8c0 //192.168.1.1
|
||||
#define MQTT_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#define MQTT_PORT 1883
|
||||
#define NTP_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#endif //TPMOBIL
|
||||
|
||||
// GPS config
|
||||
#define GPS_BAUD 9600
|
||||
#define RUN_ROUTE_DELAY 330
|
||||
|
||||
// CaptureRoute config
|
||||
#define RUN_CAPTuRE_ROUTE_DELAY 300
|
||||
|
||||
// Route config
|
||||
#define DISTANCE_BETWEEN_POINTS 0.75 // Meter
|
||||
+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
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @file moveControlConfig.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief This file inherits some configuartion for moveControl.h
|
||||
* @version 0.1
|
||||
* @date 2021-12-14
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
//Pin config
|
||||
//Left Motor
|
||||
#define M_DIR_11 27
|
||||
#define M_DIR_12 12
|
||||
#define M_PWM_1 13
|
||||
#define M_ENCODE_1A 33
|
||||
#define M_ENCODE_1B 32
|
||||
//Right Motor
|
||||
#define M_DIR_21 23
|
||||
#define M_DIR_22 14
|
||||
#define M_PWM_2 22
|
||||
#define M_ENCODE_2A 26
|
||||
#define M_ENCODE_2B 25
|
||||
|
||||
// PID config
|
||||
#define PID_OUT_MIN -100
|
||||
#define PID_OUT_MAX 100
|
||||
#define PID_SAMPLETIME 30
|
||||
// Left PID
|
||||
#define PID_LEFT_P 85
|
||||
#define PID_LEFT_I 0
|
||||
#define PID_LEFT_D 0
|
||||
// Right PID
|
||||
#define PID_RIGHT_P 75
|
||||
#define PID_RIGHT_I 0
|
||||
#define PID_RIGHT_D 0
|
||||
|
||||
// PWM
|
||||
#define PWM_CHANNEL_M1 0
|
||||
#define PWM_CHANNEL_M2 1
|
||||
|
||||
// SPEEDOMETER
|
||||
#define WHEEL_DIAMETER 0.1263
|
||||
#define ENC_STEPS 1024
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @file network.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief Some network and MQTT stuff
|
||||
* @version 0.1
|
||||
* @date 2021-12-14
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#include "networkConfig.h"
|
||||
|
||||
#define MQTT_TIME_RECONNECT 2500
|
||||
|
||||
IPAddress local_IP;
|
||||
extern IPAddress gateway;
|
||||
extern IPAddress subnet;
|
||||
extern IPAddress mqtt_server;
|
||||
|
||||
extern WiFiClient wifi_client;
|
||||
PubSubClient mqtt_client(wifi_client);
|
||||
|
||||
void setIps();
|
||||
void connectWifi();
|
||||
void setupMQTT();
|
||||
bool connectMQTT();
|
||||
void checkMQTT();
|
||||
|
||||
#endif // NETWORK_H
|
||||
@@ -0,0 +1,64 @@
|
||||
#define HW1_2
|
||||
|
||||
//Network config RHEDE
|
||||
#ifdef RHEDE
|
||||
#define WLAN_SSID "LebennigHuus"
|
||||
#define WLAN_PASSWORD "Punica-699"
|
||||
#define WLAN_IP 0x040BA8C0 //192.168.11.4
|
||||
#define WLAN_SUBNETMASK 0x0080FFFF //255.255.128.0
|
||||
#define WLAN_GATEWAY 0x0100a8c0 //192.168.0.1
|
||||
#define MQTT_SERVER 0x0701A8C0 //192.168.1.7
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_AUTH
|
||||
#define MQTT_USER "kleiax"
|
||||
#define MQTT_PASSWORD "p?{$_~5%hBM7wrcFkr55KWr#"
|
||||
#define NTP_SERVER 0x0100a8c0 //192.168.0.1
|
||||
#endif //RHEDE
|
||||
|
||||
//Network config HW1
|
||||
#ifdef HW1
|
||||
#define WLAN_SSID "hw1_gast"
|
||||
#define WLAN_PASSWORD "KeineAhnung"
|
||||
#define WLAN_IP 0x3400a8c0 //192.168.0.67
|
||||
#define WLAN_SUBNETMASK 0x00FFFFFF //255.255.255.0
|
||||
#define WLAN_GATEWAY 0x0100a8c0 //192.168.0.1
|
||||
#define MQTT_SERVER 0xD84016AC // 172.22.64.216
|
||||
#define MQTT_PORT 1883
|
||||
#define NTP_SERVER "2.de.pool.ntp.org"
|
||||
#endif //HW1
|
||||
|
||||
//Network config HW1
|
||||
#ifdef HW1_2
|
||||
#define WLAN_SSID "hw1_gast"
|
||||
#define WLAN_PASSWORD "KeineAhnung"
|
||||
#define WLAN_IP "192.168.0.67"
|
||||
#define WLAN_SUBNETMASK "255.255.255.0"
|
||||
#define WLAN_GATEWAY "192.168.0.1"
|
||||
#define MQTT_SERVER "172.22.64.216"
|
||||
#define MQTT_PORT 1883
|
||||
#define NTP_SERVER "2.de.pool.ntp.org"
|
||||
#endif //HW1
|
||||
|
||||
//Network config FRENZY
|
||||
#ifdef FRENZY
|
||||
#define WLAN_SSID "GNX7EDD84-2"
|
||||
#define WLAN_PASSWORD "2W2ZLPJ9NVQ3"
|
||||
#define WLAN_IP 0x0F01a8c0 //192.168.1.15
|
||||
#define WLAN_SUBNETMASK 0x00FFFFFF //255.255.255.0
|
||||
#define WLAN_GATEWAY 0xfe01a8c0 //192.168.1.254
|
||||
#define MQTT_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#define MQTT_PORT 1883
|
||||
#define NTP_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#endif //FRENZY
|
||||
|
||||
//Network config TPMOBIL
|
||||
#ifdef TPMOBIL
|
||||
#define WLAN_SSID "TP-Mobil"
|
||||
#define WLAN_PASSWORD "Punica-699"
|
||||
#define WLAN_IP 0x0F01a8c0 //192.168.1.15
|
||||
#define WLAN_SUBNETMASK 0x00FFFFFF //255.255.255.0
|
||||
#define WLAN_GATEWAY 0x0101a8c0 //192.168.1.1
|
||||
#define MQTT_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#define MQTT_PORT 1883
|
||||
#define NTP_SERVER 0x0201a8c0 //192.168.1.2
|
||||
#endif //TPMOBIL
|
||||
Reference in New Issue
Block a user