Christian Burri / Mbed 2 deprecated autonomous Robot Android

Dependencies:   mbed

Fork of autonomous Robot Android by Christian Burri

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers State.h Source File

State.h

00001 #ifndef _STATE_H_
00002 #define _STATE_H_
00003 
00004 #include "MaxonESCON.h"
00005 #include "RobotControl.h"
00006 #include "Task.h"
00007 #include "defines.h"
00008 
00009 /**
00010  * @author Christian Burri
00011  *
00012  * @copyright Copyright (c) 2013 HSLU Pren Team #1 Cruising Crêpe
00013  * All rights reserved.
00014  *
00015  * @brief
00016  *
00017  * State is the main mechanism for communicating current realtime system state to
00018  * the rest of the system for logging etc.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
00021  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00024  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00025  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00026  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 class State : public Task
00030 {
00031 
00032 private:
00033 
00034     state_t*            s;
00035     RobotControl*       robotControl;
00036     MaxonESCON*         motorControllerLeft;
00037     MaxonESCON*         motorControllerRight;
00038     AnalogIn            battery;
00039     Timer               timer;
00040     float               period;
00041 
00042 public:
00043 
00044     /**
00045      * @brief Creates a robot control object and initializes all private state variables.
00046      * @param s struct to read and write the state
00047      * @param robotControl Object to read the state
00048      * @param motorControllerLeft a reference to the servo drive for the left motor
00049      * @param motorControllerRight a reference to the servo drive for the right motor
00050      * @param batteryPin mbed pin for analog Input Battery Voltage
00051      * @param period the sampling period of the run loop of this controller, given in [s]
00052      */
00053     State(state_t* s,
00054           RobotControl* robotControl,
00055           MaxonESCON* motorControllerLeft,
00056           MaxonESCON* motorControllerRight,
00057           PinName batteryPin,
00058           float period);
00059 
00060     /**
00061      * @brief Destructor of the Object to destroy the Object.
00062      */
00063     virtual     ~State();
00064 
00065     /**
00066      * @brief Initzialize the File. Open the File plots.txt and set the title at first line.
00067      */
00068     void initPlotFile(void);
00069 
00070     /**
00071      * @brief Close the File.
00072      */
00073     void closePlotFile(void);
00074 
00075     /**
00076      * @brief Return the Battery voltage
00077      * state variables.
00078      * @return Batterie Voltage [V]
00079      */
00080     float readBattery();
00081 
00082     /**
00083      * @brief Starts the timer from zero.
00084      * The timer is for the logging Time.
00085      */
00086     void startTimerFromZero();
00087 
00088     /**
00089      * @brief Save the new state to a new line.
00090      */
00091     void savePlotFile(state_t s);
00092     
00093     /**
00094     * Returns the transform a  sinusvalue from -1.0 .. 1.0 to 0.0 .. 1.0
00095     * @param idx number of LEDS
00096     * @param f value till 2π
00097     * @return sinus value from 0.0f 1.0f
00098     */
00099     float dim( int idx, float f );
00100 
00101     /**
00102      * @brief Run method actualize every period.
00103      */
00104     void        run();
00105 
00106 private:
00107 
00108     void setBatteryBit();
00109 
00110     void setEnableLeftBit();
00111 
00112     void setEnableRightBit();
00113 };
00114 
00115 #endif