Q

Dependencies:   SRF05 ros_lib_kinetic TinyGPSPlus

PROJ515.hpp

Committer:
Luka_Danilovic
Date:
2019-05-08
Revision:
11:955c2ed70de2
Parent:
10:7d954fba5e7a
Child:
12:1a3272d67500

File content as of revision 11:955c2ed70de2:

#ifndef __PROJ515_H__ //Inclusion safeguards
#define __PROJ515_H__ //Definition of the inclusion
/*============================================================================*/

/* Libraries */
#include "mbed.h"                   // Mbed RTOS
#include "SRF05.h"                  // SRF05 ultrasound sensor custom libary
#include "TinyGPSPlus.h"            // GPS Module Library
#include "PololuLedStrip.h"         // LED Strip Library
#include "string"                   // Character String Library
#include "ros.h"                    // ROS Library
#include "std_msgs/String.h"        // ROS String Messages component
#include "sensor_msgs/Range.h"      // ROS Sensor Messages component
#include "sensor_msgs/NavSatFix.h"  // ROS Sensor Messages component
#include "nav_msgs/Odometry.h"      // ROS Odom   Messages component
#include "geometry_msgs/Twist.h"    // ROS Twist  Messages component

/* Definitions */
#define LEDS_OFF 0x00               // LED bus all off
#define LEDS_ON  0x07               // LED bus all on

#define USP_CF1T  PA_4              // Cliff ultrasound 1 Trigger
#define USP_CF1E  PA_3              // Cliff ultrasound 1 Echo
#define USP_CF2T  PB_0              // Cliff ultrasound 2 Trigger
#define USP_CF2E  PA_10             // Cliff ultrasound 2 Echo
#define USP_CF3T  PC_1              // Cliff ultrasound 3 Trigger
#define USP_CF3E  PB_3              // Cliff ultrasound 3 Echo
#define USP_CF4T  PC_0              // Cliff ultrasound 4 Trigger
#define USP_CF4E  PB_5              // Cliff ultrasound 4 Echo

#define USP_CB1T  PC_15              // Curb  ultrasound 1 Trigger
#define USP_CB1E  PB_4               // Curb  ultrasound 1 Echo
#define USP_CB2T  PC_14              // Curb  ultrasound 2 Trigger
#define USP_CB2E  PB_10              // Curb  ultrasound 2 Echo
#define USP_CB3T  PC_13              // Curb  ultrasound 3 Trigger
#define USP_CB3E  PA_8               // Curb  ultrasound 3 Echo
#define USP_CB4T  PB_7               // Curb  ultrasound 4 Trigger
#define USP_CB4E  PA_9               // Curb  ultrasound 4 Echo

#define GPS_TX    PC_10             // GPS Transmit Pin
#define GPS_RX    PC_11             // GPS Recieve  Pin

#define LED_F     PB_6              // LED Strip Front Data
#define LED_B     PC_7              // LED Strip Back  Data

#define FOV       1.396             // Ultrasound sensor field of view
#define MIN_RANGE 0.2               // Ultrasound sensor min range
#define MAX_RANGE 2.5               // Ultrasound sensor max range
#define CLIFF_TRH 0.1               // Robot cliff treshold
#define CLIFF_ZRO 0                 // Cliff not existent
#define EXCL_ZONE 0.255             // Robot footprint exclusion zone
#define ULTRASOUND 0x00             // Ultrasound

#define UNAGUMENTED  0x00           // Unagumented 
#define GPS_CONSTELL 0x01           // GPS constellation
#define UNNWN        0x00           // Unknown covariance
#define CVX 0x01                    // Covariance value for X from the datasheet
#define CVY 0x01                    // Covariance value for X from the datasheet
#define CVZ 0x01                    // Covariance value for X from the datasheet
#define CVO 0x00                    // Covariance value for zero components

#define LED_COUNT 30                // LED strip LED count
#define MaxVelocity 0.5             // Max Wheel Velocity

#define ROS_Baud  460800            // ROS Baud Rate
#define GPS_Baud  9600              // GPS Baud Rate
#define frameID_g "gps_odom"        // ROS frame ID

//#define PRINT_DATA 0x01             // Thread communication event to print data 

/* Namespaces */
using namespace std;                // Make all std symbols visible
using namespace ros;                // Make all ros symbols visible
using namespace sensor_msgs;        // Make all sensor_msgs symbols visible
using namespace std_msgs;           // Make all std_msgs symbols visible
using namespace nav_msgs;
using namespace Pololu;

/* Declarations */
extern float cfDist1;               // Distance returned by cliff u_sensor1 (m)
extern float cfDist2;               // Distance returned by cliff u_sensor2 (m)
extern float cfDist3;               // Distance returned by cliff u_sensor3 (m)
extern float cfDist4;               // Distance returned by cliff u_sensor4 (m)

extern float cbDist1;               // Distance returned by curb  u_sensor1 (m)
extern float cbDist2;               // Distance returned by curb  u_sensor2 (m)
extern float cbDist3;               // Distance returned by curb  u_sensor3 (m)
extern float cbDist4;               // Distance returned by curb  u_sensor4 (m)

extern float wPeriod;               // Wait period(ms) for ROS publisher

extern char  gps_c;                 // GPS stream character - Defined in PROJ515.cpp
extern int   sats_n;                // GPS satelite number  - Defined in PROJ515.cpp  

extern float vel;                   // Odom linear  velocity 
extern float ang;                   // Odom angular velocity
extern string audio_state;          // Audio Information (Playing/Stopped)

/* GPIO */
DigitalIn bttn(USER_BUTTON);        // Onboard blue user button
BusOut leds(LED1, LED2, LED3);      // Onboard LEDs bus

/* Instantiations */
// Instance for ultrasound sensors
SRF05 USS_CF1(USP_CF1T, USP_CF1E);  // Ultrasound sensor cliff 1
SRF05 USS_CF2(USP_CF2T, USP_CF2E);  // Ultrasound sensor cliff 2
SRF05 USS_CF3(USP_CF3T, USP_CF3E);  // Ultrasound sensor cliff 3
SRF05 USS_CF4(USP_CF4T, USP_CF4E);  // Ultrasound sensor cliff 4

SRF05 USS_CB1(USP_CB1T, USP_CB1E);  // Ultrasound sensor cliff 1
SRF05 USS_CB2(USP_CB2T, USP_CB2E);  // Ultrasound sensor cliff 2
SRF05 USS_CB3(USP_CB3T, USP_CB3E);  // Ultrasound sensor cliff 3
SRF05 USS_CB4(USP_CB4T, USP_CB4E);  // Ultrasound sensor cliff 4

// Instance for GPS
TinyGPSPlus gpsModule;              // Instance of GPS class
Serial gpsSer(GPS_TX, GPS_RX);      // Instance of Serial class to gps

// Instance for LED Strip
PololuLedStrip ledStripFront(LED_F);// LED Strip Front
PololuLedStrip ledStripBack(LED_B); // LED Strip Back
rgb_color colors[LED_COUNT];        // RGB Colour Array

// Instance for ROS node and messages
NodeHandle nh;                      // Instance for ROS Node Handler

Range ultrasound_msg_cf1;           // Instance for ROS Range message 1
Range ultrasound_msg_cf2;           // Instance for ROS Range message 2
Range ultrasound_msg_cf3;           // Instance for ROS Range message 3
Range ultrasound_msg_cf4;           // Instance for ROS Range message 4
Range ultrasound_msg_cb1;           // Instance for ROS Range message 5
Range ultrasound_msg_cb2;           // Instance for ROS Range message 6
Range ultrasound_msg_cb3;           // Instance for ROS Range message 7
Range ultrasound_msg_cb4;           // Instance for ROS Range message 8

NavSatFix gps_odom_msg;             // Instance for ROS NavSatFix message

// Instance for ROS publishers
Publisher ultrasound_pub_cf1("ultrasound/cf1", &ultrasound_msg_cf1); 
Publisher ultrasound_pub_cf2("ultrasound/cf2", &ultrasound_msg_cf2); 
Publisher ultrasound_pub_cf3("ultrasound/cf3", &ultrasound_msg_cf3); 
Publisher ultrasound_pub_cf4("ultrasound/cf4", &ultrasound_msg_cf4); 
Publisher ultrasound_pub_cb1("ultrasound/cb1", &ultrasound_msg_cb1); 
Publisher ultrasound_pub_cb2("ultrasound/cb2", &ultrasound_msg_cb2); 
Publisher ultrasound_pub_cb3("ultrasound/cb3", &ultrasound_msg_cb3); 
Publisher ultrasound_pub_cb4("ultrasound/cb4", &ultrasound_msg_cb4); 

Publisher gps_odom_pub("gps_odom", &gps_odom_msg);

/* Threads and Signals */
//Thread myThread (osPriorityNormal);
//EventFlags myEventFlag;

/* Function Prototypes */
void startSensors();                // Start the Sensors
void recordDist();                  // Record the Distances (meters)
void checkCliff();                  // Check the Cliff Sensors Readings
void advRosPub();                   // Adverstise Ultrasound Topic
void setupRosMsg();                 // Setup the message constant values
void setRosDist();                  // Put distance in ROS messages
void setRosStamp();                 // Put time into ROS messages
void publishRosMsg();               // Publish ROS messages
//void AudioStatusCB(const std_msgs::String &status);
//void VelocityCB(const nav_msgs::Odometry &odom);
float Map(float x, float in_min, float in_max, float out_min, float out_max);

/*============================================================================*/
#endif // End of inclusion