Template for LPC1768
Dependencies: Gimbal MLX90620 Socket lwip-eth lwip-sys lwip mbed-rtos mbed
Fork of EkkoEye by
CGimbal.h@53:72f350a6d09c, 2016-04-14 (annotated)
- Committer:
- Mike
- Date:
- Thu Apr 14 13:45:38 2016 +0100
- Revision:
- 53:72f350a6d09c
DCW
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike | 53:72f350a6d09c | 1 | /* |
Mike | 53:72f350a6d09c | 2 | * CGimbal.h |
Mike | 53:72f350a6d09c | 3 | * |
Mike | 53:72f350a6d09c | 4 | * Created on: 15 Feb 2016 |
Mike | 53:72f350a6d09c | 5 | * Author: mike |
Mike | 53:72f350a6d09c | 6 | */ |
Mike | 53:72f350a6d09c | 7 | #ifndef CGIMBAL_H_ |
Mike | 53:72f350a6d09c | 8 | #define CGIMBAL_H_ |
Mike | 53:72f350a6d09c | 9 | |
Mike | 53:72f350a6d09c | 10 | #include "mbed.h" |
Mike | 53:72f350a6d09c | 11 | |
Mike | 53:72f350a6d09c | 12 | #define FORWARD 0 // Used for the direction pin |
Mike | 53:72f350a6d09c | 13 | #define REVERSE 1 // Used for the direction pin |
Mike | 53:72f350a6d09c | 14 | #define CLOCKWISE 0 // Used for the direction pin |
Mike | 53:72f350a6d09c | 15 | #define ANTICLOCKWISE 1 // Used for the direction pin |
Mike | 53:72f350a6d09c | 16 | #define DFT_STEP_PULSE 0.00002 // 20us is recommended pulse width for most stepper drivers |
Mike | 53:72f350a6d09c | 17 | #define X_AXIS 0 // Used for Tour array indexing |
Mike | 53:72f350a6d09c | 18 | #define Y_AXIS 1 // Used for Tour array indexing |
Mike | 53:72f350a6d09c | 19 | #define NUM_AXES 2 // Used for Tour array indexing |
Mike | 53:72f350a6d09c | 20 | #define DEGREES_PER_STEP .1125 // 0.45 & 200 steps per revolution give 360/3200 degrees per step (1/16microsteps) |
Mike | 53:72f350a6d09c | 21 | #define DFT_STEP_INTERVAL 250 // Normal time interval between pulses (5ms = 250 * 20us) |
Mike | 53:72f350a6d09c | 22 | #define HOME_STEP_INTERVAL 500 // Moves more slowly when homing (10ms = 250 * 20us) |
Mike | 53:72f350a6d09c | 23 | #define MAX_TOUR 10 // Maximum number of way-points that can be performed in a single tour |
Mike | 53:72f350a6d09c | 24 | |
Mike | 53:72f350a6d09c | 25 | class CGimbal |
Mike | 53:72f350a6d09c | 26 | { |
Mike | 53:72f350a6d09c | 27 | public: |
Mike | 53:72f350a6d09c | 28 | |
Mike | 53:72f350a6d09c | 29 | DigitalOut * m_pXStepPin; // Pointer to the X axis step pin |
Mike | 53:72f350a6d09c | 30 | DigitalOut * m_pXDirPin; // Pointer to the Y axis step pin |
Mike | 53:72f350a6d09c | 31 | DigitalOut * m_pYStepPin; // Pointer to the X axis direction pin |
Mike | 53:72f350a6d09c | 32 | DigitalOut * m_pYDirPin; // Pointer to the Y axis direction pin |
Mike | 53:72f350a6d09c | 33 | |
Mike | 53:72f350a6d09c | 34 | // Constructor |
Mike | 53:72f350a6d09c | 35 | CGimbal(DigitalOut * pXStepPin, DigitalOut * pXDirPin, DigitalOut * pYStepPin, DigitalOut * pYDirPin); |
Mike | 53:72f350a6d09c | 36 | |
Mike | 53:72f350a6d09c | 37 | // Destructor |
Mike | 53:72f350a6d09c | 38 | ~CGimbal(); |
Mike | 53:72f350a6d09c | 39 | |
Mike | 53:72f350a6d09c | 40 | void Zero(void); |
Mike | 53:72f350a6d09c | 41 | void Home(void); // Move to the Home position |
Mike | 53:72f350a6d09c | 42 | int MoveRel(); // Move (x, y) relative to current position |
Mike | 53:72f350a6d09c | 43 | int MoveAbs(float x, float y); // Move to Absolute (x,y) position |
Mike | 53:72f350a6d09c | 44 | int RotateAbs(float xAngle, float yAngle); // Rotate to Absolute (x,y) angle in degrees |
Mike | 53:72f350a6d09c | 45 | int TourPoint(int n); // Execute a tour using n stored waypoints |
Mike | 53:72f350a6d09c | 46 | void MeanderScan(void); // Perform a full sweep at increments of (60, 15) degrees |
Mike | 53:72f350a6d09c | 47 | |
Mike | 53:72f350a6d09c | 48 | int m_StepInterval; // The time in 10us increments between each Step pulse (ie 100 = 1ms) |
Mike | 53:72f350a6d09c | 49 | int m_AbsoluteXPos; // The current motor x axis position in steps (800 per revolution) |
Mike | 53:72f350a6d09c | 50 | int m_AbsoluteYPos; // The current motor y axis position in steps (800 per revolution) |
Mike | 53:72f350a6d09c | 51 | |
Mike | 53:72f350a6d09c | 52 | float m_AbsoluteXAngle; // The current motor x axis angle in degrees |
Mike | 53:72f350a6d09c | 53 | float m_AbsoluteYAngle; // The current motor y axis angle in degrees |
Mike | 53:72f350a6d09c | 54 | |
Mike | 53:72f350a6d09c | 55 | int m_xSteps; // Tracks the number of required x steps (+/-) when moving relative or absolute |
Mike | 53:72f350a6d09c | 56 | int m_ySteps; // Tracks the number of required y steps (+/-) when moving relative or absolute |
Mike | 53:72f350a6d09c | 57 | int m_xPulses; // Tracks the number of required x pulses when moving (always a positive value) |
Mike | 53:72f350a6d09c | 58 | int m_yPulses; // Tracks the number of required y pulses when moving (always a positive value) |
Mike | 53:72f350a6d09c | 59 | int m_xDir; // X Direction: Used internally when moving, calculated from m_xSteps 1 to move ccw, 0 to move cw |
Mike | 53:72f350a6d09c | 60 | int m_yDir; // Y Direction: Used internally when moving, calculated from m_xSteps 1 to move ccw, 0 to move cw |
Mike | 53:72f350a6d09c | 61 | |
Mike | 53:72f350a6d09c | 62 | int m_NumWaypoints; |
Mike | 53:72f350a6d09c | 63 | float m_TourPoints [NUM_AXES] [MAX_TOUR]; // Used to store the x,y way-points received from the server |
Mike | 53:72f350a6d09c | 64 | float m_PointTemperature [MAX_TOUR]; // Used to store the x,y way-points received from the server |
Mike | 53:72f350a6d09c | 65 | |
Mike | 53:72f350a6d09c | 66 | |
Mike | 53:72f350a6d09c | 67 | int m_TickCount; // Used to track the number of 10us Ticks that have occurred to ensure consistent motor speed |
Mike | 53:72f350a6d09c | 68 | |
Mike | 53:72f350a6d09c | 69 | }; |
Mike | 53:72f350a6d09c | 70 | |
Mike | 53:72f350a6d09c | 71 | |
Mike | 53:72f350a6d09c | 72 | |
Mike | 53:72f350a6d09c | 73 | |
Mike | 53:72f350a6d09c | 74 | #endif /* CGIMBAL_H_ */ |