This program is for an autonomous robot for the competition at the Hochschule Luzern. http://cruisingcrepe.wordpress.com/ We are one of the 32 teams. http://cruisingcrepe.wordpress.com/ The postition control is based on this Documentation: Control of Wheeled Mobile Robots: An Experimental Overview from Alessandro De Luca, Giuseppe Oriolo, Marilena Vendittelli. For more information see here: http://www.dis.uniroma1.it/~labrob/pub/papers/Ramsete01.pdf
Fork of autonomous Robot Android by
State/State.h@39:a4fd6206da89, 2013-06-10 (annotated)
- Committer:
- chrigelburri
- Date:
- Mon Jun 10 14:40:37 2013 +0000
- Revision:
- 39:a4fd6206da89
- Parent:
- 38:d76e488e725f
V1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chrigelburri | 0:31f7be68e52d | 1 | #ifndef _STATE_H_ |
chrigelburri | 0:31f7be68e52d | 2 | #define _STATE_H_ |
chrigelburri | 0:31f7be68e52d | 3 | |
chrigelburri | 0:31f7be68e52d | 4 | #include "MaxonESCON.h" |
chrigelburri | 0:31f7be68e52d | 5 | #include "RobotControl.h" |
chrigelburri | 0:31f7be68e52d | 6 | #include "Task.h" |
chrigelburri | 0:31f7be68e52d | 7 | #include "defines.h" |
chrigelburri | 0:31f7be68e52d | 8 | |
chrigelburri | 0:31f7be68e52d | 9 | /** |
chrigelburri | 0:31f7be68e52d | 10 | * @author Christian Burri |
chrigelburri | 0:31f7be68e52d | 11 | * |
chrigelburri | 38:d76e488e725f | 12 | * @copyright Copyright (c) 2013 HSLU Pren Team #1 Cruising Crêpe |
chrigelburri | 0:31f7be68e52d | 13 | * All rights reserved. |
chrigelburri | 0:31f7be68e52d | 14 | * |
chrigelburri | 11:775ebb69d5e1 | 15 | * @brief |
chrigelburri | 0:31f7be68e52d | 16 | * |
chrigelburri | 0:31f7be68e52d | 17 | * State is the main mechanism for communicating current realtime system state to |
chrigelburri | 0:31f7be68e52d | 18 | * the rest of the system for logging etc. |
chrigelburri | 6:48eeb41188dd | 19 | * |
chrigelburri | 38:d76e488e725f | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
chrigelburri | 38:d76e488e725f | 21 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
chrigelburri | 38:d76e488e725f | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
chrigelburri | 38:d76e488e725f | 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
chrigelburri | 38:d76e488e725f | 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
chrigelburri | 38:d76e488e725f | 25 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
chrigelburri | 38:d76e488e725f | 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
chrigelburri | 0:31f7be68e52d | 27 | */ |
chrigelburri | 0:31f7be68e52d | 28 | |
chrigelburri | 0:31f7be68e52d | 29 | class State : public Task |
chrigelburri | 0:31f7be68e52d | 30 | { |
chrigelburri | 0:31f7be68e52d | 31 | |
chrigelburri | 0:31f7be68e52d | 32 | private: |
chrigelburri | 0:31f7be68e52d | 33 | |
chrigelburri | 11:775ebb69d5e1 | 34 | state_t* s; |
chrigelburri | 0:31f7be68e52d | 35 | RobotControl* robotControl; |
chrigelburri | 0:31f7be68e52d | 36 | MaxonESCON* motorControllerLeft; |
chrigelburri | 0:31f7be68e52d | 37 | MaxonESCON* motorControllerRight; |
chrigelburri | 11:775ebb69d5e1 | 38 | AnalogIn battery; |
chrigelburri | 0:31f7be68e52d | 39 | Timer timer; |
chrigelburri | 0:31f7be68e52d | 40 | float period; |
chrigelburri | 0:31f7be68e52d | 41 | |
chrigelburri | 0:31f7be68e52d | 42 | public: |
chrigelburri | 0:31f7be68e52d | 43 | |
chrigelburri | 0:31f7be68e52d | 44 | /** |
chrigelburri | 11:775ebb69d5e1 | 45 | * @brief Creates a robot control object and initializes all private state variables. |
chrigelburri | 3:92ba0254af87 | 46 | * @param s struct to read and write the state |
chrigelburri | 3:92ba0254af87 | 47 | * @param robotControl Object to read the state |
chrigelburri | 3:92ba0254af87 | 48 | * @param motorControllerLeft a reference to the servo drive for the left motor |
chrigelburri | 3:92ba0254af87 | 49 | * @param motorControllerRight a reference to the servo drive for the right motor |
chrigelburri | 11:775ebb69d5e1 | 50 | * @param batteryPin mbed pin for analog Input Battery Voltage |
chrigelburri | 3:92ba0254af87 | 51 | * @param period the sampling period of the run loop of this controller, given in [s] |
chrigelburri | 0:31f7be68e52d | 52 | */ |
chrigelburri | 6:48eeb41188dd | 53 | State(state_t* s, |
chrigelburri | 6:48eeb41188dd | 54 | RobotControl* robotControl, |
chrigelburri | 6:48eeb41188dd | 55 | MaxonESCON* motorControllerLeft, |
chrigelburri | 6:48eeb41188dd | 56 | MaxonESCON* motorControllerRight, |
chrigelburri | 11:775ebb69d5e1 | 57 | PinName batteryPin, |
chrigelburri | 6:48eeb41188dd | 58 | float period); |
chrigelburri | 0:31f7be68e52d | 59 | |
chrigelburri | 0:31f7be68e52d | 60 | /** |
chrigelburri | 11:775ebb69d5e1 | 61 | * @brief Destructor of the Object to destroy the Object. |
chrigelburri | 12:235e318a414f | 62 | */ |
chrigelburri | 0:31f7be68e52d | 63 | virtual ~State(); |
chrigelburri | 6:48eeb41188dd | 64 | |
chrigelburri | 0:31f7be68e52d | 65 | /** |
chrigelburri | 11:775ebb69d5e1 | 66 | * @brief Initzialize the File. Open the File plots.txt and set the title at first line. |
chrigelburri | 0:31f7be68e52d | 67 | */ |
chrigelburri | 0:31f7be68e52d | 68 | void initPlotFile(void); |
chrigelburri | 0:31f7be68e52d | 69 | |
chrigelburri | 0:31f7be68e52d | 70 | /** |
chrigelburri | 11:775ebb69d5e1 | 71 | * @brief Close the File. |
chrigelburri | 6:48eeb41188dd | 72 | */ |
chrigelburri | 0:31f7be68e52d | 73 | void closePlotFile(void); |
chrigelburri | 0:31f7be68e52d | 74 | |
chrigelburri | 0:31f7be68e52d | 75 | /** |
chrigelburri | 11:775ebb69d5e1 | 76 | * @brief Return the Battery voltage |
chrigelburri | 0:31f7be68e52d | 77 | * state variables. |
chrigelburri | 0:31f7be68e52d | 78 | * @return Batterie Voltage [V] |
chrigelburri | 0:31f7be68e52d | 79 | */ |
chrigelburri | 0:31f7be68e52d | 80 | float readBattery(); |
chrigelburri | 0:31f7be68e52d | 81 | |
chrigelburri | 6:48eeb41188dd | 82 | /** |
chrigelburri | 11:775ebb69d5e1 | 83 | * @brief Starts the timer from zero. |
chrigelburri | 1:6cd533a712c6 | 84 | * The timer is for the logging Time. |
chrigelburri | 1:6cd533a712c6 | 85 | */ |
chrigelburri | 0:31f7be68e52d | 86 | void startTimerFromZero(); |
chrigelburri | 0:31f7be68e52d | 87 | |
chrigelburri | 0:31f7be68e52d | 88 | /** |
chrigelburri | 11:775ebb69d5e1 | 89 | * @brief Save the new state to a new line. |
chrigelburri | 6:48eeb41188dd | 90 | */ |
chrigelburri | 0:31f7be68e52d | 91 | void savePlotFile(state_t s); |
chrigelburri | 24:08241be546ba | 92 | |
chrigelburri | 24:08241be546ba | 93 | /** |
chrigelburri | 24:08241be546ba | 94 | * Returns the transform a sinusvalue from -1.0 .. 1.0 to 0.0 .. 1.0 |
chrigelburri | 24:08241be546ba | 95 | * @param idx number of LEDS |
chrigelburri | 24:08241be546ba | 96 | * @param f value till 2π |
chrigelburri | 24:08241be546ba | 97 | * @return sinus value from 0.0f 1.0f |
chrigelburri | 24:08241be546ba | 98 | */ |
chrigelburri | 24:08241be546ba | 99 | float dim( int idx, float f ); |
chrigelburri | 0:31f7be68e52d | 100 | |
chrigelburri | 11:775ebb69d5e1 | 101 | /** |
chrigelburri | 12:235e318a414f | 102 | * @brief Run method actualize every period. |
chrigelburri | 12:235e318a414f | 103 | */ |
chrigelburri | 0:31f7be68e52d | 104 | void run(); |
chrigelburri | 0:31f7be68e52d | 105 | |
chrigelburri | 0:31f7be68e52d | 106 | private: |
chrigelburri | 0:31f7be68e52d | 107 | |
chrigelburri | 0:31f7be68e52d | 108 | void setBatteryBit(); |
chrigelburri | 0:31f7be68e52d | 109 | |
chrigelburri | 0:31f7be68e52d | 110 | void setEnableLeftBit(); |
chrigelburri | 0:31f7be68e52d | 111 | |
chrigelburri | 0:31f7be68e52d | 112 | void setEnableRightBit(); |
chrigelburri | 0:31f7be68e52d | 113 | }; |
chrigelburri | 0:31f7be68e52d | 114 | |
chrigelburri | 0:31f7be68e52d | 115 | #endif |