![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
sra-romi
Dependencies: BufferedSerial Matrix
Robot.h@4:1defb279922a, 2021-05-11 (annotated)
- Committer:
- joaopsousa99
- Date:
- Tue May 11 18:10:22 2021 +0000
- Revision:
- 4:1defb279922a
- Parent:
- 1:dc87724abce8
as.djvblaskdvj
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabiofaria | 1:dc87724abce8 | 1 | /** @file */ |
fabiofaria | 1:dc87724abce8 | 2 | #ifndef ROBOT_H_ |
fabiofaria | 1:dc87724abce8 | 3 | #define ROBOT_H_ |
fabiofaria | 1:dc87724abce8 | 4 | |
fabiofaria | 1:dc87724abce8 | 5 | #include "mbed.h" |
joaopsousa99 | 4:1defb279922a | 6 | #include <cstdint> |
joaopsousa99 | 4:1defb279922a | 7 | |
joaopsousa99 | 4:1defb279922a | 8 | extern const int16_t COUNTS_PER_ROTATION; |
joaopsousa99 | 4:1defb279922a | 9 | extern const int16_t WHEEL_DIAMETER; |
joaopsousa99 | 4:1defb279922a | 10 | extern const int16_t WHEEL_DISTANCE; |
joaopsousa99 | 4:1defb279922a | 11 | extern const float MAX_LIN_VEL; |
joaopsousa99 | 4:1defb279922a | 12 | extern const float MIN_LIN_VEL; |
joaopsousa99 | 4:1defb279922a | 13 | extern const float MIN_SET_SPEEDS; |
joaopsousa99 | 4:1defb279922a | 14 | extern const float MAX_SET_SPEEDS; |
fabiofaria | 1:dc87724abce8 | 15 | |
fabiofaria | 1:dc87724abce8 | 16 | extern int16_t countsLeft; |
fabiofaria | 1:dc87724abce8 | 17 | extern int16_t countsRight; |
fabiofaria | 1:dc87724abce8 | 18 | |
joaopsousa99 | 4:1defb279922a | 19 | extern float poseX; |
joaopsousa99 | 4:1defb279922a | 20 | extern float poseY; |
joaopsousa99 | 4:1defb279922a | 21 | extern float poseTheta; |
joaopsousa99 | 4:1defb279922a | 22 | |
fabiofaria | 1:dc87724abce8 | 23 | /** \brief Sets the speed for both motors. |
fabiofaria | 1:dc87724abce8 | 24 | * |
fabiofaria | 1:dc87724abce8 | 25 | * \param leftSpeed A number from -300 to 300 representing the speed and |
fabiofaria | 1:dc87724abce8 | 26 | * direction of the left motor. Values of -300 or less result in full speed |
fabiofaria | 1:dc87724abce8 | 27 | * reverse, and values of 300 or more result in full speed forward. |
fabiofaria | 1:dc87724abce8 | 28 | * \param rightSpeed A number from -300 to 300 representing the speed and |
fabiofaria | 1:dc87724abce8 | 29 | * direction of the right motor. Values of -300 or less result in full speed |
fabiofaria | 1:dc87724abce8 | 30 | * reverse, and values of 300 or more result in full speed forward. */ |
fabiofaria | 1:dc87724abce8 | 31 | void setSpeeds(int16_t leftSpeed, int16_t rightSpeed); |
fabiofaria | 1:dc87724abce8 | 32 | |
fabiofaria | 1:dc87724abce8 | 33 | /** \brief Sets the speed for the left motor. |
fabiofaria | 1:dc87724abce8 | 34 | * |
fabiofaria | 1:dc87724abce8 | 35 | * \param speed A number from -300 to 300 representing the speed and |
fabiofaria | 1:dc87724abce8 | 36 | * direction of the left motor. Values of -300 or less result in full speed |
fabiofaria | 1:dc87724abce8 | 37 | * reverse, and values of 300 or more result in full speed forward. */ |
fabiofaria | 1:dc87724abce8 | 38 | void setLeftSpeed(int16_t speed); |
fabiofaria | 1:dc87724abce8 | 39 | |
fabiofaria | 1:dc87724abce8 | 40 | /** \brief Sets the speed for the right motor. |
fabiofaria | 1:dc87724abce8 | 41 | * |
fabiofaria | 1:dc87724abce8 | 42 | * \param speed A number from -300 to 300 representing the speed and |
fabiofaria | 1:dc87724abce8 | 43 | * direction of the right motor. Values of -300 or less result in full speed |
fabiofaria | 1:dc87724abce8 | 44 | * reverse, and values of 300 or more result in full speed forward. */ |
fabiofaria | 1:dc87724abce8 | 45 | void setRightSpeed(int16_t speed); |
fabiofaria | 1:dc87724abce8 | 46 | |
fabiofaria | 1:dc87724abce8 | 47 | /*! Returns the number of counts that have been detected from the both |
fabiofaria | 1:dc87724abce8 | 48 | * encoders. These counts start at 0. Positive counts correspond to forward |
fabiofaria | 1:dc87724abce8 | 49 | * movement of the wheel of the Romi, while negative counts correspond |
fabiofaria | 1:dc87724abce8 | 50 | * to backwards movement. |
fabiofaria | 1:dc87724abce8 | 51 | * |
fabiofaria | 1:dc87724abce8 | 52 | * The count is returned as a signed 16-bit integer. When the count goes |
fabiofaria | 1:dc87724abce8 | 53 | * over 32767, it will overflow down to -32768. When the count goes below |
fabiofaria | 1:dc87724abce8 | 54 | * -32768, it will overflow up to 32767. */ |
fabiofaria | 1:dc87724abce8 | 55 | void getCounts(); |
fabiofaria | 1:dc87724abce8 | 56 | |
fabiofaria | 1:dc87724abce8 | 57 | /*! This function is just like getCounts() except it also clears the |
fabiofaria | 1:dc87724abce8 | 58 | * counts before returning. If you call this frequently enough, you will |
fabiofaria | 1:dc87724abce8 | 59 | * not have to worry about the count overflowing. */ |
fabiofaria | 1:dc87724abce8 | 60 | void getCountsAndReset(); |
fabiofaria | 1:dc87724abce8 | 61 | |
joaopsousa99 | 4:1defb279922a | 62 | void updatePose(); |
joaopsousa99 | 4:1defb279922a | 63 | |
joaopsousa99 | 4:1defb279922a | 64 | void robotVel2wheelVel(float v, float w, float *wheelSpeeds); |
joaopsousa99 | 4:1defb279922a | 65 | |
joaopsousa99 | 4:1defb279922a | 66 | float mapSpeeds(float value); |
joaopsousa99 | 4:1defb279922a | 67 | |
fabiofaria | 1:dc87724abce8 | 68 | #endif /* ROBOT_H_ */ |