this code is completely restructured, but should do the same thing. did not want to directly commit, since it may not work at all. compiles though.

Dependencies:   AVEncoder mbed-src-AV

Fork of Test by 2015-2016_Mouserat

mouse.h

Committer:
jimmery
Date:
2015-12-15
Revision:
13:5f08195456a4

File content as of revision 13:5f08195456a4:

// HAS EVERYTHING RELATED TO THE MOUSE.
// includes implementations from: 
// mouse.cpp, which includes all motor related actions. 
// sensors.cpp, which includes all sensor information. 
// pid.cpp, which includes the pid constants/algorithm. 
// maze.cpp? when that gets implemented in the future. 

#ifndef MOUSE_H
#define MOUSE_H

#include "AVEncoder.h"

typedef enum 
{
    LEFT, 
    RIGHT,
    AROUND, 
    INVALID
} TURN_DIRECTION;

// this is just so that we can maintain what state our mouse is in. 
// currently this has no real use, but it may in the future. 
// or we could just remove this entirely. 
typedef enum 
{
    STOPPED, 
    FORWARD, 
    TURNING,
    MOVECELL,
    FINISHED, 
    UNKNOWN
} STATE;

class Mouse
{
public:
    Mouse();
    void stop();
    void setForward( float left_speed, float right_speed );
    void turn( TURN_DIRECTION dir = LEFT, int n_times = 1 );
    void move_cell();
    
    void scan();
    void sensor_reset();
    void offsetCalc();
    bool forward_wall_detected();
    bool side_opening_detected();
    
    void run_pid();
    void pid_reset();
    
    // TODO move into private eventually.
    volatile TURN_DIRECTION turn_direction;
    volatile STATE mouse_state;
private:
    // essential mouse information. 
    volatile int row;
    volatile int col;
    
    volatile float left_speed;
    volatile float right_speed;
    
    // [-----------------------------------SENSOR INFORMATION-----------------------------------]
    // [-------------------------------IMPLEMENTED IN SENSORS.CPP-------------------------------] 
    void sensor_init();
    
    volatile float gyro_offset;

    volatile float lf_val;
    volatile float rf_val;
    volatile float ls_val;
    volatile float rs_val;
    
    volatile int wall_in_front;
    volatile int opening_left_ahead;
    volatile int opening_right_ahead;
    volatile int opening_left;
    volatile int opening_right;
    
    // [------------------------------------PID INFORMATION.------------------------------------]
    // [---------------------------------IMPLEMENTED IN PID.CPP---------------------------------] 
    // helper functions
    float rotational_pid();
    float translational_pid();
    //void pid_reset();
    
    // helper data members. (not really needed to be shown - for implementation purposes)
    volatile float line_prevError;
    volatile float enco_prevError;
    volatile float gyro_prevError;
    
    volatile float set_w;
    volatile float set_x;
    
    volatile float spin_enco_weight;
    volatile float spin_gyro_weight;
    
    // [-------------------------------------TEST FUNCTIONS-------------------------------------]
    // [--------------------------------IMPLEMENTED IN TEST.CPP.--------------------------------] 
    
    void test_IR_sensors();
    void test_motors();
};

#endif