-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathAxisCalibration.h
70 lines (58 loc) · 3.1 KB
/
AxisCalibration.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef AXIS_CALIBRATION_H
#define AXIS_CALIBRATION_H
#include <Arduino.h>
#include "Multiplexer.h"
#include "defines.h"
#include <Encoder.h>
// Structure to hold the configuration of the axis
typedef struct {
bool blError; // true if a timeout occurred
int16_t iMin; // Minimum value
int16_t iMax; // Maximum value
bool blMotorInverted; // true if the motor direction is inverted
bool blEncoderInverted; // true if the encoder counting direction is inverted
bool blAxisTimeout;
bool blTimeout;
} AxisConfiguration;
class Axis {
private:
Multiplexer* multiplexer; // Pointer to a multiplexer object
byte motorPinLeft; // Pin for left motor control
byte motorPinRight; // Pin for right motor control
bool blEndSwitchLeft; // Pointer to left end switch status
bool blEndSwitchRight; // Pointer to right end switch status
bool blIsRoll; // is Roll or Pitch
Encoder* encoder; // Pointer to the encoder object
byte speed; // Current speed of the motor
unsigned long lastMovementTime; // Timestamp of the last movement
// Configuration constants
static const byte maxSpeed = CALIBRATION_MAX_SPEED; // Maximum speed
static const unsigned long timeout = CALIBRATION_AXIS_MOVEMENT_TIMEOUT; // Timeout of 4 seconds for no movement
static const unsigned long calibrationTimeout = CALIBRATION_TIMEOUT; // Timeout of 20 seconds for calibration
static const byte speedIncrement = CALIBRATION_SPEED_INCREMENT; // Speed increment value
static const byte whileDelay = CALIBRATION_WHILE_DELAY; // delay inside while to give Arduino time to work
static const byte waitDelayMotorStops =CALIBRATION_WHILE_DELAY_MOTOR_STOPS; // delay inside while to give Arduino time to work
static const byte waitDelayAfterMoveOutEndstop =CALIBRATION_DELAY_MOVE_OUT_OF_ENDSTOP; // not too fast
// Calibration start time
unsigned long calibrationStartTime;
// Axis configuration object
AxisConfiguration config;
// Helper method to manage motor movement
void ManageMovement(bool direction, unsigned long& lastMovementTime, int& lastEncoderValue, bool& speedIncreased);
void ReadMultiplexer();
int ResetEncoder();
bool CheckTimeouts(unsigned long lastMovementTime, unsigned long calibrationStartTime);
public:
// Constructor to initialize motor pins and end switches
//Axis(int motorLeftPin, int motorRightPin, bool* endSwitchLeft, bool* endSwitchRight, Encoder* encoder, Multiplexer* multiplexerPtr);
Axis(int motorLeftPin, int motorRightPin, bool isRoll, Encoder* encoder, Multiplexer* multiplexerPtr);
// Method to move the motor in a given direction
void MoveMotor(bool direction);
// Method to stop the motor
void StopMotor();
// Calibration method for the axis
void Calibrate();
// Method to get the current axis configuration
AxisConfiguration GetConfiguration();
};
#endif