Marco Newman / CartesianRobot

Dependents:   CartesianRobot_Demo

Committer:
marcoanewman
Date:
Thu Dec 16 04:33:27 2021 +0000
Revision:
1:0b705e9f84ce
Parent:
0:5af6295f4ec9
consistency fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcoanewman 0:5af6295f4ec9 1 #ifndef CARTESIANROBOT_H
marcoanewman 0:5af6295f4ec9 2 #define CARTESIANROBOT_H
marcoanewman 0:5af6295f4ec9 3
marcoanewman 0:5af6295f4ec9 4 #include "Stepper.h"
marcoanewman 0:5af6295f4ec9 5 #include "rtos.h"
marcoanewman 0:5af6295f4ec9 6
marcoanewman 0:5af6295f4ec9 7 #define BUFFER_MAX_SIZE 10
marcoanewman 0:5af6295f4ec9 8
marcoanewman 0:5af6295f4ec9 9 class CartesianRobot
marcoanewman 0:5af6295f4ec9 10 {
marcoanewman 0:5af6295f4ec9 11 public:
marcoanewman 0:5af6295f4ec9 12 // Constructor
marcoanewman 0:5af6295f4ec9 13 CartesianRobot(
marcoanewman 0:5af6295f4ec9 14 PinName x_step, PinName x_dir, PinName x_en,
marcoanewman 0:5af6295f4ec9 15 PinName y_step, PinName y_dir, PinName y_en,
marcoanewman 0:5af6295f4ec9 16 PinName z_step, PinName z_dir, PinName z_en
marcoanewman 0:5af6295f4ec9 17 );
marcoanewman 0:5af6295f4ec9 18 // Destructor
marcoanewman 0:5af6295f4ec9 19 ~CartesianRobot();
marcoanewman 0:5af6295f4ec9 20
marcoanewman 0:5af6295f4ec9 21 // Add motion to buffer
marcoanewman 0:5af6295f4ec9 22 void moveToXYZ(
marcoanewman 0:5af6295f4ec9 23 int x_pos, int y_pos, int z_pos,
marcoanewman 0:5af6295f4ec9 24 float x_speed, float y_speed, float z_speed
marcoanewman 0:5af6295f4ec9 25 );
marcoanewman 0:5af6295f4ec9 26 // Move robot to absolute position
marcoanewman 0:5af6295f4ec9 27 void goToXYZ(int x_pos, int y_pos, int z_pos);
marcoanewman 0:5af6295f4ec9 28 // Move motors a set number of steps
marcoanewman 0:5af6295f4ec9 29 void moveX(int steps);
marcoanewman 0:5af6295f4ec9 30 void moveY(int steps);
marcoanewman 0:5af6295f4ec9 31 void moveZ(int steps);
marcoanewman 0:5af6295f4ec9 32
marcoanewman 0:5af6295f4ec9 33 // Set motor speeds [steps/sec]
marcoanewman 0:5af6295f4ec9 34 void setXSpeed(float speed);
marcoanewman 0:5af6295f4ec9 35 void setYSpeed(float speed);
marcoanewman 0:5af6295f4ec9 36 void setZSpeed(float speed);
marcoanewman 0:5af6295f4ec9 37 // Set motor acceleration ramps [steps/sec²] (0 = infinite acceleration)
marcoanewman 1:0b705e9f84ce 38 void setXAcc(float acc);
marcoanewman 1:0b705e9f84ce 39 void setYAcc(float acc);
marcoanewman 1:0b705e9f84ce 40 void setZAcc(float acc);
marcoanewman 0:5af6295f4ec9 41 // Set motor deceleration ramps [steps/sec²] (0 = infinite deceleration)
marcoanewman 1:0b705e9f84ce 42 void setXDec(float dec);
marcoanewman 1:0b705e9f84ce 43 void setYDec(float dec);
marcoanewman 1:0b705e9f84ce 44 void setZDec(float dec);
marcoanewman 0:5af6295f4ec9 45
marcoanewman 0:5af6295f4ec9 46 // Enable motor drivers
marcoanewman 0:5af6295f4ec9 47 void enable(void);
marcoanewman 0:5af6295f4ec9 48 // Disable motor drivers
marcoanewman 0:5af6295f4ec9 49 void disable(void);
marcoanewman 0:5af6295f4ec9 50 // Check if motor drivers are enabled
marcoanewman 0:5af6295f4ec9 51 bool enabled(void);
marcoanewman 0:5af6295f4ec9 52 // Check if motors are stopped
marcoanewman 0:5af6295f4ec9 53 bool stopped(void);
marcoanewman 0:5af6295f4ec9 54 // Get absolute positions from origin
marcoanewman 0:5af6295f4ec9 55 int getXPosition(void);
marcoanewman 0:5af6295f4ec9 56 int getYPosition(void);
marcoanewman 0:5af6295f4ec9 57 int getZPosition(void);
marcoanewman 0:5af6295f4ec9 58
marcoanewman 0:5af6295f4ec9 59 // Set origin for absolute motion
marcoanewman 0:5af6295f4ec9 60 void setOrigin(void);
marcoanewman 0:5af6295f4ec9 61 // Set limits for absolute motion
marcoanewman 0:5af6295f4ec9 62 void setLimits(void);
marcoanewman 0:5af6295f4ec9 63 // Get limits for absolute motion
marcoanewman 0:5af6295f4ec9 64 int getXLimit(void);
marcoanewman 0:5af6295f4ec9 65 int getYLimit(void);
marcoanewman 0:5af6295f4ec9 66 int getZLimit(void);
marcoanewman 0:5af6295f4ec9 67
marcoanewman 0:5af6295f4ec9 68 // Start buffer management thread
marcoanewman 0:5af6295f4ec9 69 void startManager(void);
marcoanewman 0:5af6295f4ec9 70
marcoanewman 0:5af6295f4ec9 71 private:
marcoanewman 0:5af6295f4ec9 72 Stepper _x_stepper; // x axis stepper object
marcoanewman 0:5af6295f4ec9 73 Stepper _y_stepper; // y axis stepper object
marcoanewman 0:5af6295f4ec9 74 Stepper _z_stepper; // z axis stepper object
marcoanewman 0:5af6295f4ec9 75
marcoanewman 0:5af6295f4ec9 76 Mutex _buffer_mutex; // thread safe buffer
marcoanewman 0:5af6295f4ec9 77 int _buffer_size; // current buffer size
marcoanewman 0:5af6295f4ec9 78 int _x_buffer_pos[BUFFER_MAX_SIZE]; // x position buffer
marcoanewman 0:5af6295f4ec9 79 int _y_buffer_pos[BUFFER_MAX_SIZE]; // y position buffer
marcoanewman 0:5af6295f4ec9 80 int _z_buffer_pos[BUFFER_MAX_SIZE]; // z position buffer
marcoanewman 0:5af6295f4ec9 81 float _x_buffer_speed[BUFFER_MAX_SIZE]; // x speed buffer
marcoanewman 0:5af6295f4ec9 82 float _y_buffer_speed[BUFFER_MAX_SIZE]; // y speed buffer
marcoanewman 0:5af6295f4ec9 83 float _z_buffer_speed[BUFFER_MAX_SIZE]; // z speed buffer
marcoanewman 0:5af6295f4ec9 84
marcoanewman 0:5af6295f4ec9 85 // buffer management
marcoanewman 0:5af6295f4ec9 86 Thread* _thread;
marcoanewman 0:5af6295f4ec9 87 static void manager(void const *p);
marcoanewman 0:5af6295f4ec9 88
marcoanewman 0:5af6295f4ec9 89 };
marcoanewman 0:5af6295f4ec9 90
marcoanewman 0:5af6295f4ec9 91 #endif