ROVER - API changes to the roverapp tasks. Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
diff --git a/rover/include/drivers/oled_drivers/ArduiPi_SSD1306.h b/rover/include/drivers/oled_drivers/ArduiPi_SSD1306.h index c5c2aaf..d52264f 100644 --- a/rover/include/drivers/oled_drivers/ArduiPi_SSD1306.h +++ b/rover/include/drivers/oled_drivers/ArduiPi_SSD1306.h
@@ -66,7 +66,7 @@ #define _BV(bit) (1 << (bit)) // GCC Missing -#define max(a,b) (a>b?a:b) -#define min(a,b) (a<b?a:b) +//#define max(a,b) (a>b?a:b) +//#define min(a,b) (a<b?a:b) #endif
diff --git a/rover/include/interfaces.h b/rover/include/interfaces.h index ce68494..041204f 100644 --- a/rover/include/interfaces.h +++ b/rover/include/interfaces.h
@@ -152,6 +152,8 @@ extern int shutdown_hook_shared; +extern int display_use_elsewhere_shared; + /* For proper termination */ extern int running_flag;
diff --git a/rover/include/libraries/hono_interaction/hono_interaction.h b/rover/include/libraries/hono_interaction/hono_interaction.h index 9550b2e..38f458b 100644 --- a/rover/include/libraries/hono_interaction/hono_interaction.h +++ b/rover/include/libraries/hono_interaction/hono_interaction.h
@@ -21,15 +21,15 @@ //Defines //#define DEBUG_HTTP_RESPONSE 1 -#define DEBUG_DEVICE_REGISTRATION 1 +//#define DEBUG_DEVICE_REGISTRATION 1 //Interfaces int registerEntriesToHonoInstance (void); int registerDeviceToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id); -int sendTelemetryDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * field, double value); -int sendEventDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * field, double value); +int sendTelemetryDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password, char * field, double value); +int sendEventDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password, char * field, double value); int handleCode(int code); #endif /* HONO_INTERACTION_HONO_INTERACTION_H_ */
diff --git a/rover/include/libraries/status_library/status_library.h b/rover/include/libraries/status_library/status_library.h index 9549c31..b48690b 100644 --- a/rover/include/libraries/status_library/status_library.h +++ b/rover/include/libraries/status_library/status_library.h
@@ -22,6 +22,6 @@ int retrieveETHStatus (void); int retrieveINTERNETStatus (void); int retrieveBLUETOOTHStatus (void); -int retrieveHONOStatus (void); +int retrieveHONOStatus (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password); #endif /* STATUS_LIBRARY_STATUS_LIBRARY_H_ */
diff --git a/rover/include/roverapp.h b/rover/include/roverapp.h index ce21a8d..69221d7 100644 --- a/rover/include/roverapp.h +++ b/rover/include/roverapp.h
@@ -28,8 +28,25 @@ #include <iostream> #include <stdlib.h> #include <unistd.h> -#include "wiringPi.h" #include "interfaces.h" -#endif /* RASPBERRYTEST_H_ */ +#include <roverapi/rover_api.hpp> + +//Use the following when cross compiling with Eclipse CDT SDK +//#define CROSS_COMPILE_ECLIPSE 1 + +//When debugging without RoverSenseLayer uncomment the following to prevent OS to shutdown. +//#define DEBUG_WO_RSL 1 + +//Please comment the line below to work with SR-04 sensor instead of GROOVE for rear proximity sensing. +//#define USE_GROOVE_SENSOR 1 + +//Using rover namespace from Rover API +using namespace rover; + +extern RoverBase r; + +extern pthread_t oled_thread; + +#endif /* ROVERAPP_H_ */
diff --git a/rover/include/tasks/external_gpio_task.h b/rover/include/tasks/external_gpio_task.h index ea3e3f1..5b5a5a3 100644 --- a/rover/include/tasks/external_gpio_task.h +++ b/rover/include/tasks/external_gpio_task.h
@@ -19,26 +19,7 @@ #include <stdio.h> #include <stdlib.h> -/* Defines */ - -/* Buzzer */ -#define BUZZER_PIN 28 //BCM-20, wiringpi 28 -#define BUZZER_ON_FREQ 200 -#define BUZZER_SHUTDOWN_FREQ 300 -#define BUZZER_OFF_FREQ 0 - -/* Shutdown Button */ -#define SHUTDOWN_BUTTON_PIN 24 //BCM-21, wiringpi 24 - -/* User Button */ -#define USER_BUTTON_PIN 27 //BCM-16, wiringpi 27 - /* Interfaces */ void *External_GPIO_Task(void * arg); -void turnBuzzerOn (void); -void turnBuzzerOff (void); -void playShutdownTone (void); -void playOffTone (void); -void shutdownOS (void); #endif /* TASKS_EXTERNAL_GPIO_TASK_H_ */
diff --git a/rover/include/tasks/oled_task.h b/rover/include/tasks/oled_task.h index 3afc6b7..82d86c3 100644 --- a/rover/include/tasks/oled_task.h +++ b/rover/include/tasks/oled_task.h
@@ -43,13 +43,8 @@ #define TASKS_OLED_TASK_H_ /* Defines */ -#define NUMFLAKES 10 -#define XPOS 0 -#define YPOS 1 -#define DELTAY 2 /* Intefaces */ void *OLED_Task(void * arg); -void shutdownOSwithDisplay(void); #endif /* TASKS_OLED_TASK_H_ */
diff --git a/rover/include/tasks/rover_test_task.h b/rover/include/tasks/rover_test_task.h index a9a6848..4112fad 100644 --- a/rover/include/tasks/rover_test_task.h +++ b/rover/include/tasks/rover_test_task.h
@@ -27,7 +27,7 @@ #include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> +#include <roverapi/basic_psys_rover.h> #include <interfaces.h>
diff --git a/rover/include/tasks/temperature_task.h b/rover/include/tasks/temperature_task.h index f89b4c9..ccb895a 100644 --- a/rover/include/tasks/temperature_task.h +++ b/rover/include/tasks/temperature_task.h
@@ -26,9 +26,6 @@ #include <stdio.h> #include <stdlib.h> -#define MAX_TIMINGS 85 - -#define DHT22_RPI_PIN 24 //BCM19, wiringPi 24 void *Temperature_Task(void * arg);
diff --git a/rover/include/tasks/ultrasonic_sensor_grove_task.h b/rover/include/tasks/ultrasonic_sensor_grove_task.h index f79d806..712f93f 100644 --- a/rover/include/tasks/ultrasonic_sensor_grove_task.h +++ b/rover/include/tasks/ultrasonic_sensor_grove_task.h
@@ -32,13 +32,6 @@ #include <stdio.h> #include <stdlib.h> - - - -#define SIG 2 //BCM-27 -> WiringPi 2 //Same as ECHO1 pin, if some one wants to replace back sr04 with groove sensor - void *Ultrasonic_Sensor_Grove_Task(void *); -int getCM_GrooveUltrasonicRanger(); -void setup_GrooveUltrasonicRanger(); #endif /* ULTRASONIC_SENSOR_GROVE_TASK_H_ */
diff --git a/rover/include/tasks/ultrasonic_sensor_sr04_back_task.h b/rover/include/tasks/ultrasonic_sensor_sr04_back_task.h index 13e454b..c5a72be 100644 --- a/rover/include/tasks/ultrasonic_sensor_sr04_back_task.h +++ b/rover/include/tasks/ultrasonic_sensor_sr04_back_task.h
@@ -49,14 +49,6 @@ #include <stdio.h> #include <stdlib.h> - - -#define TRIG1 1 //BCM-18 -> WiringPi 1 -#define ECHO1 2 //BCM-27 -> WiringPi 2 - void *Ultrasonic_Sensor_SR04_Back_Task(void *); -int getCM_HCSR04UltrasonicBack(); -void setup_HCSR04UltrasonicBack(); - #endif /* TASKS_ULTRASONIC_SENSOR_SR04_BACK_TASK_H_ */
diff --git a/rover/include/tasks/ultrasonic_sensor_sr04_front_task.h b/rover/include/tasks/ultrasonic_sensor_sr04_front_task.h index 36a8a77..6be96a4 100644 --- a/rover/include/tasks/ultrasonic_sensor_sr04_front_task.h +++ b/rover/include/tasks/ultrasonic_sensor_sr04_front_task.h
@@ -49,14 +49,7 @@ #include <stdio.h> #include <stdlib.h> - - -#define TRIG0 7 //BCM-4 -> WiringPi 7 -#define ECHO0 0 //BCM-17 -> WiringPi 0 - void *Ultrasonic_Sensor_SR04_Front_Task(void *); -int getCM_HCSR04UltrasonicFront(); -void setup_HCSR04UltrasonicFront(); #endif /* TASKS_ULTRASONIC_SENSOR_SR04_FRONT_TASK_H_ */
diff --git a/rover/src/drivers/oled_drivers/appstacle_logo.c b/rover/src/drivers/oled_drivers/appstacle_logo.c index 711dce1..052afd2 100644 --- a/rover/src/drivers/oled_drivers/appstacle_logo.c +++ b/rover/src/drivers/oled_drivers/appstacle_logo.c
@@ -16,68 +16,68 @@ #ifndef APPSTACLE_LOGO_ #define APPSTACLE_LOGO_ -static unsigned char appstacle_logo [] = { // 128x64 +static unsigned char appstacle_logo [] = { // 128x64 //Kuksa logo 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xC0, 0x00, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFE, 0x00, 0x00, 0x1F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xE0, 0x3F, 0xFF, 0x01, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x81, 0xFF, 0xFF, 0xE0, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x07, 0xFF, 0xFF, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0F, 0xFF, 0xFF, 0xFE, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xE0, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x1F, 0xFE, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x7F, 0xFF, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01, 0xFF, 0xFF, 0xE0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x03, 0xFF, 0xFF, 0xF0, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x07, 0xF0, 0x07, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x03, 0xC0, 0x00, 0xF0, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x01, 0x80, 0x00, 0x60, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x07, 0xF0, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3F, 0xFF, 0x80, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x03, 0xFF, 0xFF, 0xF8, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x3F, 0xFE, 0x1F, 0xFF, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0xFC, 0x0F, 0xFF, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF8, 0x07, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xF0, 0x03, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x01, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x01, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x01, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xE0, 0x01, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x0F, 0xF0, 0x03, 0xFE, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x03, 0xF8, 0x07, 0xF0, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x01, 0xFC, 0x0F, 0xE0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xFE, 0x1F, 0x80, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x3F, 0xFF, 0x80, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3F, 0xFF, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x1F, 0xFE, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x1F, 0xFE, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x0F, 0xFC, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x0F, 0xFC, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x07, 0xFC, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x07, 0xF8, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x07, 0xF8, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xF0, 0x07, 0xF8, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF8, 0x07, 0xF8, 0x07, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFE, 0x07, 0xF8, 0x1F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x07, 0xF8, 0x3F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xE7, 0xF9, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xFF, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x77, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x01, 0xF7, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x07, 0xF7, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x1F, 0xF7, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x7F, 0xF7, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0xFF, 0xF7, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x03, 0xFF, 0xF0, 0x03, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x07, 0xFD, 0xF0, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x0F, 0xF1, 0xF0, 0x00, 0x3F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x1F, 0xC1, 0xF0, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x3F, 0x81, 0xF0, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x3F, 0x01, 0xF0, 0x00, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x7E, 0x01, 0xF0, 0x0C, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xFC, 0x01, 0xF0, 0x3E, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xFC, 0x01, 0xF0, 0x3E, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x01, 0xF8, 0x01, 0xF0, 0x3E, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x01, 0xF0, 0x01, 0xF0, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x01, 0xF0, 0x01, 0xF0, 0x7E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x03, 0xE0, 0x01, 0xF0, 0x7E, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x03, 0xE0, 0x01, 0xF0, 0xFE, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x03, 0xE0, 0x01, 0xF1, 0xFC, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x07, 0xE0, 0x01, 0xF3, 0xFC, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x07, 0xC0, 0x01, 0xF3, 0xF8, 0x00, 0x0F, 0x80, 0xC7, 0x06, 0x1C, 0x31, 0xC1, 0xF8, 0x03, 0x00, +0x07, 0xC0, 0x01, 0xF9, 0xF0, 0x00, 0x0F, 0x80, 0xCE, 0x06, 0x18, 0x33, 0x83, 0x9C, 0x07, 0x80, +0x07, 0xC0, 0x01, 0xFC, 0x60, 0x00, 0x0F, 0x80, 0xDC, 0x06, 0x18, 0x37, 0x03, 0x1C, 0x07, 0x80, +0x07, 0xC0, 0x01, 0xFF, 0x80, 0x00, 0x0F, 0x80, 0xD8, 0x06, 0x18, 0x36, 0x03, 0x80, 0x0C, 0xC0, +0x07, 0xC0, 0x01, 0xFF, 0xC0, 0x00, 0x0F, 0x80, 0xF0, 0x06, 0x18, 0x3C, 0x01, 0xF0, 0x0C, 0xC0, +0x07, 0xC0, 0x00, 0x3F, 0xE0, 0x00, 0x0F, 0x80, 0xF8, 0x06, 0x18, 0x3E, 0x01, 0xFC, 0x0C, 0xC0, +0x07, 0xE0, 0x01, 0x8F, 0xF0, 0x00, 0x0F, 0x80, 0xDC, 0x06, 0x18, 0x37, 0x00, 0x0C, 0x1C, 0xE0, +0x07, 0xE0, 0x01, 0xE3, 0xF8, 0x00, 0x1F, 0x80, 0xDC, 0x06, 0x18, 0x37, 0x03, 0x0C, 0x18, 0x60, +0x07, 0xE0, 0x01, 0xF1, 0xFC, 0x00, 0x1F, 0x80, 0xCE, 0x07, 0x38, 0x33, 0x83, 0x9C, 0x38, 0x70, +0x03, 0xE0, 0x01, 0xF0, 0xFE, 0x00, 0x1F, 0x80, 0xC7, 0x03, 0xF0, 0x31, 0xC1, 0xF8, 0x30, 0x30, +0x03, 0xE0, 0x01, 0xF0, 0x7E, 0x00, 0x1F, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, +0x03, 0xF0, 0x01, 0xF0, 0x7E, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x01, 0xF0, 0x01, 0xF0, 0x3E, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x01, 0xF8, 0x01, 0xF0, 0x3E, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xF8, 0x01, 0xF0, 0x3E, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0xFC, 0x01, 0xF0, 0x3E, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x7E, 0x01, 0xF0, 0x3E, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x7F, 0x01, 0xF0, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x3F, 0x81, 0xF0, 0x00, 0x07, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x1F, 0xC1, 0xF0, 0x00, 0x0F, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x0F, 0xE1, 0xF0, 0x00, 0x1F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x07, 0xF9, 0xF0, 0x00, 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x03, 0xFD, 0xF0, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x01, 0xFD, 0xF0, 0x1F, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0xFD, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x7D, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x3D, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x1D, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
diff --git a/rover/src/libraries/hono_interaction/hono_interaction.cpp b/rover/src/libraries/hono_interaction/hono_interaction.cpp index b248a9a..986a695 100644 --- a/rover/src/libraries/hono_interaction/hono_interaction.cpp +++ b/rover/src/libraries/hono_interaction/hono_interaction.cpp
@@ -182,7 +182,7 @@ * If the action completed -> returns 1 * If the action failed -> returns 0 */ -int sendTelemetryDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * field, double value) +int sendTelemetryDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password, char * field, double value) { FILE *fp; int code; @@ -197,9 +197,13 @@ //To get the information in dashboard, we use device ID as the entry name, and "value" as field. //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"value": 0.5}' http://idial.institute:8080/telemetry/DEFAULT_TENANT/roverRearSensor" - sprintf(buffer, "curl -X POST -i -u sensor1@"); + sprintf(buffer, "curl -X POST -i -u "); + strcat(buffer, user); + strcat(buffer, "@"); strcat(buffer, tenant_name); - strcat(buffer, ":hono-secret -H 'Content-Type: application/json' --data-binary '{\""); + strcat(buffer, ":"); + strcat(buffer, password); + strcat(buffer, " -H 'Content-Type: application/json' --data-binary '{\""); strcat(buffer, field); strcat(buffer, "\": "); @@ -271,7 +275,7 @@ * If the action completed -> returns 1 * If the action failed -> returns 0 */ -int sendEventDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * field, double value) +int sendEventDataToHonoInstance (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password, char * field, double value) { FILE *fp; int code; @@ -286,9 +290,13 @@ //To get the information in dashboard, we use device ID as the entry name, and "value" as field. //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"value": 0.5}' http://idial.institute:8080/event/DEFAULT_TENANT/roverRearSensor" - sprintf(buffer, "curl -X POST -i -u sensor1@"); + sprintf(buffer, "curl -X POST -i -u "); + strcat(buffer, user); + strcat(buffer, "@"); strcat(buffer, tenant_name); - strcat(buffer, ":hono-secret -H 'Content-Type: application/json' --data-binary '{\""); + strcat(buffer, ":"); + strcat(buffer, password); + strcat(buffer, " -H 'Content-Type: application/json' --data-binary '{\""); strcat(buffer, field); strcat(buffer, "\": "); @@ -344,29 +352,4 @@ return status; } -/** - * Function Name: registerSensorsToHonoInstance - * Description: If non registered already, this function - * registers all the sensors and other entries - * of APP4MC Rover as devices to Hono instance. - * for visualization of Raw data in Granafa/InfluxDB. - */ -int registerEntriesToHonoInstance (void) -{ - /*registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverFront"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverFrontLeft"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverFrontRight"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverRear"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverRearLeft"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverRearRight"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverBearing"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu1"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu2"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu3"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "roverUtilCpu4"); - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "connectionCheck");*/ - registerDeviceToHonoInstance("idial.institute",28080,"DEFAULT_TENANT", "4711"); - - return 1; -}
diff --git a/rover/src/libraries/status_library/status_library.cpp b/rover/src/libraries/status_library/status_library.cpp index 28400ef..0620733 100644 --- a/rover/src/libraries/status_library/status_library.cpp +++ b/rover/src/libraries/status_library/status_library.cpp
@@ -15,6 +15,7 @@ #include <stdint.h> #include <stdio.h> +#include <string.h> #include <libraries/status_library/status_library.h> #include <libraries/hono_interaction/hono_interaction.h> @@ -161,4 +162,73 @@ } } +int retrieveHONOStatus (char * host_name, int port, char * tenant_name, char * device_id, char * user, char * password) +{ + FILE *fp; + int code; + int status; + + char buffer[256]; + char num_buffer[33]; + + //Prepare command as string + //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"Bearing": 0.5}' http://idial.institute:8080/telemetry/DEFAULT_TENANT/4711" + + //For Hono 0.5-M9 + //Example: "curl -X POST -i -u sensor1@DEFAULT_TENANT:hono-secret -H 'Content-Type: application/json' --data-binary '{"temp": 5}' http://idial.institute:8080/telemetry" + + //To get the information in dashboard, we use device ID as the entry name, and "value" as field. + //Example: "curl -X PUT -i -H 'Content-Type: application/json' --data-binary '{"value": 0.5}' http://idial.institute:8080/telemetry/DEFAULT_TENANT/roverRearSensor" + + sprintf(buffer, "curl -X POST -i -u "); + strcat(buffer, user); + strcat(buffer, "@"); + strcat(buffer, tenant_name); + strcat(buffer, ":"); + strcat(buffer, password); + strcat(buffer, " -H 'Content-Type: application/json' --data-binary '{\""); + + strcat(buffer, "datacheck"); + strcat(buffer, "\": "); + snprintf(num_buffer, sizeof(num_buffer), "%f", 1.0); + strcat(buffer, num_buffer); + num_buffer[0] = 0; //Clear array + + strcat(buffer, "}' http://"); + strcat(buffer, host_name); + strcat(buffer, ":"); + snprintf(num_buffer, sizeof(num_buffer), "%d", port); + strcat(buffer, num_buffer); + num_buffer[0] = 0; //Clear array + strcat(buffer, "/telemetry"); + + //To redirect pipe to prevent stdout showing all outputs generated by curl + strcat(buffer, " 2>/dev/null"); //2>&1 would redirect to stderr, we choose to be able to parse returned code + + //Execute the command + fp = popen(buffer,"r"); + + //Get and Parse the output + fgets(buffer, 13, fp); //Get the string HTTP/1.1 XXX + + //Prepare the response code + sscanf(buffer, "HTTP/1.1 %d", &code); + + /* Debug */ + //printf("Response=%s\n",buffer); + + /* Get status */ + status = handleCode(code); + + /* Return */ + if (status == 1) + { + return 1; + } + else + { + return 0; + } +} +
diff --git a/rover/src/roverapp.cpp b/rover/src/roverapp.cpp index 773794a..ef8c0bf 100644 --- a/rover/src/roverapp.cpp +++ b/rover/src/roverapp.cpp
@@ -25,7 +25,6 @@ #include <libraries/pthread_distribution_lib/pthread_distribution.h> #include <libraries/pthread_monitoring/collect_thread_name.h> -#include <libraries/hono_interaction/hono_interaction.h> #include <libraries/timing/timing.h> #include <tasks/ultrasonic_sensor_grove_task.h> @@ -51,16 +50,18 @@ #include <tasks/socket_client_task.h> #include <tasks/socket_server_task.h> -#include <api/basic_psys_rover.h> - #include <interfaces.h> #include <signal.h> -//Please comment the line below to work with SR-04 sensor instead of GROOVE for rear proximity sensing. -//#define USE_GROOVE_SENSOR 1 using namespace std; +//Using rover namespace from Rover API +using namespace rover; + +//Create global RoverBase object from Rover API +RoverBase r; + /* Threads */ pthread_t ultrasonic_grove_thread; pthread_t ultrasonic_sr04_front_thread; @@ -196,6 +197,8 @@ int shutdown_hook_shared; +int display_use_elsewhere_shared; + /* For proper termination */ int running_flag; @@ -225,22 +228,20 @@ int main() { - //Register all the entries as devices to cloud - registerEntriesToHonoInstance(); + //Initialize all rover components + r.initialize(); + + //Set-up hono instance attributes and register 4711 device to Hono + r.inRoverCloud().setHono("idial.institute", 8080, "DEFAULT_TENANT"); + + r.inRoverCloud().setRegistrationPort(28080); + r.inRoverCloud().registerDevice("4711"); /* Add signals to exit threads properly */ signal(SIGINT, exitHandler); signal(SIGTERM, exitHandler); signal(SIGKILL, exitHandler); - RefreshThreadList(); - - CollectProcessID(); - - CollectThreadName("Main_Thread"); - - wiringPiSetup(); - //Initialize shared data temperature_shared = 0.0; humidity_shared = 0.0; @@ -254,10 +255,11 @@ infrared_shared[3] = 0.0; bearing_shared = 0.0; driving_mode = MANUAL; - speed_shared = FULL_SPEED; + speed_shared = r.inRoverDriving().HIGHEST_SPEED; buzzer_status_shared = 0; shutdown_hook_shared = 0; running_flag = 1; + display_use_elsewhere_shared = 0; //Initialize mutexes pthread_mutex_init(&temperature_lock, NULL); @@ -480,10 +482,13 @@ placeAThreadToCore (webserver_motordrive_thread, 0); */ + + while (running_flag) { //What main thread does should come here.. // ... + delayMicroseconds(1* SECONDS_TO_MICROSECONDS); } pthread_exit(NULL);
diff --git a/rover/src/tasks/adaptive_cruise_control_task.cpp b/rover/src/tasks/adaptive_cruise_control_task.cpp index 5e0403d..79234cb 100644 --- a/rover/src/tasks/adaptive_cruise_control_task.cpp +++ b/rover/src/tasks/adaptive_cruise_control_task.cpp
@@ -11,17 +11,13 @@ #include <tasks/adaptive_cruise_control_task.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <roverapp.h> -#include <softPwm.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> +#include <roverapp.h> void *Adaptive_Cruise_Control_Task(void * arg) { @@ -30,8 +26,6 @@ acc_task_tmr.setDeadline(0.1); acc_task_tmr.setPeriod(0.1); - CollectThreadName("Adaptive_Cruise_Control_Task"); - while (1) { acc_task_tmr.recordStartTime(); @@ -49,24 +43,33 @@ { // go back if distance ok if (distance_sr04_back_shared < CRITICAL_DISTANCE) - stop(); + r.inRoverDriving().stopRover(); else - go(BACKWARD, LOW_SPEED); + { + r.inRoverDriving().setSpeed(r.inRoverDriving().LOWEST_SPEED); + r.inRoverDriving().goBackward(); + } } // front distance between correct and critical else if (distance_sr04_front_shared < CORRECT_DISTANCE && distance_sr04_front_shared >= CRITICAL_DISTANCE) { - stop(); + r.inRoverDriving().stopRover(); } // front distance between safe and correct else if (distance_sr04_front_shared < SAFE_DISTANCE && distance_sr04_front_shared >= CORRECT_DISTANCE) - go(FORWARD, LOW_SPEED); + { + r.inRoverDriving().setSpeed(r.inRoverDriving().LOWEST_SPEED); + r.inRoverDriving().goForward(); + } // distance > safe else if (distance_sr04_front_shared >= SAFE_DISTANCE) - go(FORWARD, speed_shared); + { + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().goForward(); + } // printf("ACC mode is ON!\n");
diff --git a/rover/src/tasks/bluetooth_task.cpp b/rover/src/tasks/bluetooth_task.cpp index a4542a9..6501b4f 100644 --- a/rover/src/tasks/bluetooth_task.cpp +++ b/rover/src/tasks/bluetooth_task.cpp
@@ -54,22 +54,18 @@ #include <tasks/bluetooth_task.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <roverapp.h> - -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <sys/socket.h> #include <bluetooth/bluetooth.h> /* Important Note: RFCOMM socket type is supported by Android API, so we chose to use it */ #include <bluetooth/rfcomm.h> +#include <roverapp.h> void *Bluetooth_Task (void * arg) { @@ -78,8 +74,6 @@ bluetooth_task_tmr.setDeadline(1); bluetooth_task_tmr.setPeriod(1); - CollectThreadName("BLE_Task"); - /* Bluetooth Setup (RFCOMM socket, server) */ struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 }; char buf[1024] = { 0 };
diff --git a/rover/src/tasks/booth_modes_task.cpp b/rover/src/tasks/booth_modes_task.cpp index 1a09cd7..cf2bb31 100644 --- a/rover/src/tasks/booth_modes_task.cpp +++ b/rover/src/tasks/booth_modes_task.cpp
@@ -15,17 +15,14 @@ #include <tasks/booth_modes_task.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <roverapp.h> #include <softPwm.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> +#include <roverapp.h> void *Booth_Modes_Task(void * arg) { @@ -34,8 +31,6 @@ booth_task_tmr.setDeadline(0.1); booth_task_tmr.setPeriod(0.1); - CollectThreadName("Booth_Modes_Task"); - while (1) { booth_task_tmr.recordStartTime();
diff --git a/rover/src/tasks/compass_sensor_task.cpp b/rover/src/tasks/compass_sensor_task.cpp index 59aa154..1260dc4 100644 --- a/rover/src/tasks/compass_sensor_task.cpp +++ b/rover/src/tasks/compass_sensor_task.cpp
@@ -19,117 +19,19 @@ * 22.03.2017 - initial revision * */ + #include <tasks/compass_sensor_task.h> #include <stdint.h> #include <ctime> -#include <wiringPi.h> -#include <wiringPiI2C.h> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <math.h> -#include <fstream> -#include <iostream> - -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -#define HMC588L_ADDRESS 0x1E -#define CALIBRATION_DURATION 10000 //compass calibration has a duration of 5 seconds -#define DECLINATION_ANGLE 0.0413 //correction factor for location Paderborn - -static int i2c_hmc588l_fd = -1; -static unsigned int calibration_start = 0; - -static int16_t xMinRaw = 0; -static int16_t xMaxRaw = 0; -static int16_t yMaxRaw = 0; -static int16_t yMinRaw = 0; - -void setupCompassSensor() { - - if ((i2c_hmc588l_fd = wiringPiI2CSetup(HMC588L_ADDRESS)) < 0) { - printf("Failed to initialize HMC588L compass sensor"); - } - - if (i2c_hmc588l_fd >= 0) { - int8_t gain = 5; - - wiringPiI2CWriteReg8(i2c_hmc588l_fd, 0x00, 0x70); // 8-average, 15 Hz default, positive self test measurement - wiringPiI2CWriteReg8(i2c_hmc588l_fd, 0x01, gain << 5); // Gain - wiringPiI2CWriteReg8(i2c_hmc588l_fd, 0x02, 0x00); // Continuous-measurement mode - } - - calibration_start = millis(); -} - -float getBearingFromSensor() { - - int8_t buffer[6]; - //potential optimization: wiringPiI2CReadReg16 - buffer[0] = wiringPiI2CReadReg8(i2c_hmc588l_fd, 0x03); - buffer[1] = wiringPiI2CReadReg8(i2c_hmc588l_fd, 0x04); - buffer[2] = wiringPiI2CReadReg8(i2c_hmc588l_fd, 0x05); - buffer[3] = wiringPiI2CReadReg8(i2c_hmc588l_fd, 0x06); - buffer[4] = wiringPiI2CReadReg8(i2c_hmc588l_fd, 0x07); - buffer[5] = wiringPiI2CReadReg8(i2c_hmc588l_fd, 0x08); - - int16_t xRaw = (((int16_t) buffer[0] << 8) & 0xff00) | buffer[1]; - //int16_t zRaw = (((int16_t) buffer[2] << 8) & 0xff00) | buffer[3]; - int16_t yRaw = (((int16_t) buffer[4] << 8) & 0xff00) | buffer[5]; - - //if calibration is active calculate minimum and maximum x/y values for calibration - if (millis() <= calibration_start + CALIBRATION_DURATION) { - if (xRaw < xMinRaw) { - xMinRaw = xRaw; - } - if (xRaw > xMaxRaw) { - xMaxRaw = xRaw; - } - if (yRaw < yMinRaw) { - yMinRaw = yRaw; - } - if (yRaw > yMaxRaw) { - yMaxRaw = yRaw; - } - } - - //calibration: move and scale x coordinates based on minimum and maximum values to get a unit circle - float xf = xRaw - (float) (xMinRaw + xMaxRaw) / 2.0f; - xf = xf / (xMinRaw + xMaxRaw) * 2.0f; - - //calibration: move and scale y coordinates based on minimum and maximum values to get a unit circle - float yf = yRaw - (float) (yMinRaw + yMaxRaw) / 2.0f; - yf = yf / (yMinRaw + yMaxRaw) * 2.0f; - - float bearing = atan2(yf, xf); - - //location specific magnetic field correction - bearing += DECLINATION_ANGLE; - - if (bearing < 0) { - bearing += 2 * M_PI; - } - - if (bearing > 2 * M_PI) { - bearing -= 2 * M_PI; - } - - float headingDegrees = bearing * (180.0 / M_PI); - - return headingDegrees; -} - int EndCalibrationMode (void) { - //Write to text file .. - ofstream myfile; - myfile.open("/var/www/html/ROVER_CMD.inc"); - myfile << "F"; - myfile.close(); pthread_mutex_lock(&keycommand_lock); keycommand_shared = 'f'; pthread_mutex_unlock(&keycommand_lock); @@ -141,14 +43,10 @@ timing compass_task_tmr; char local_command = 'f'; - CollectThreadName("CompassSensor_Task"); - compass_task_tmr.setTaskID("Compass-Sensor"); compass_task_tmr.setDeadline(0.1); compass_task_tmr.setPeriod(0.1); - setupCompassSensor(); - while (1) { compass_task_tmr.recordStartTime(); compass_task_tmr.calculatePreviousSlackTime(); @@ -161,18 +59,16 @@ { printf("Starting compass calibration for 5 seconds. Please rotate me 360 degrees.\n"); EndCalibrationMode(); - calibration_start = millis(); + r.inRoverSensors().calibrateBearingSensor(); //Calibration state.. //At the end of calibration to go to the end of calibration mode call EndCalibrationMode() } //Asynchronous end to calibration mode --> Call EndCalibrationMode() - if (i2c_hmc588l_fd >= 0) { - pthread_mutex_lock(&compass_lock); - bearing_shared = getBearingFromSensor(); - pthread_mutex_unlock(&compass_lock); - //printf("Bearing=%f\n", bearing_shared); - } + pthread_mutex_lock(&compass_lock); + bearing_shared = r.inRoverSensors().readBearing(); + pthread_mutex_unlock(&compass_lock); + //Task content ends here ------------------------------------------------- compass_task_tmr.recordEndTime();
diff --git a/rover/src/tasks/cpu_logger_task.cpp b/rover/src/tasks/cpu_logger_task.cpp index c36aa15..ef7a82d 100644 --- a/rover/src/tasks/cpu_logger_task.cpp +++ b/rover/src/tasks/cpu_logger_task.cpp
@@ -18,49 +18,16 @@ */ #include <tasks/cpu_logger_task.h> -#include <string.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <roverapp.h> -#include <softPwm.h> - -#include <libraries/pthread_monitoring/collect_thread_name.h> /* Signal header */ #include <signal.h> -/* Reads a certain file which returns core usage and exits with EX_OK or EX_SOFTWARE */ -float* retrieveCoreUtilization (void) -{ - FILE *fp; - char buffer[128]; - float util[5]; - size_t bytes_read; - - /* Execute the command */ - fp = popen("python /opt/rover-app/scripts/read_core_usage.py ","r"); - - /* Read to buffer */ - bytes_read = fread(buffer, 1, sizeof(buffer), fp); - - if (bytes_read == 0 || bytes_read == sizeof(buffer)) - perror("Can't read from /opt/rover-app/scripts/read_core_usage.py"); - - buffer[bytes_read] = '\0'; - - //printf("buf:%s\n",buffer); - - /* Parse */ - sscanf(buffer,"[%f, %f, %f, %f]",&util[0], &util[1], &util[2], &util[3]); - - /* Return */ - return util; -} +#include <roverapp.h> void Cpu_Logger_Task_Terminator (int dummy) { @@ -75,8 +42,6 @@ cpu_logger_task_tmr.setDeadline(3); cpu_logger_task_tmr.setPeriod(3); - CollectThreadName("Cpu_Logger_Task"); - /* Add termination signal handler to properly close fd */ signal(SIGINT, Cpu_Logger_Task_Terminator); signal(SIGTERM, Cpu_Logger_Task_Terminator); @@ -91,7 +56,7 @@ //Task content starts here ----------------------------------------------- - util = retrieveCoreUtilization(); + util = r.inRoverUtils().getCoreUtilization(); pthread_mutex_lock(&cpu_util_shared_lock); cpu_util_shared[0] = util[0]; cpu_util_shared[1] = util[1];
diff --git a/rover/src/tasks/display_sensors_task.cpp b/rover/src/tasks/display_sensors_task.cpp index 1a9708b..f35469e 100644 --- a/rover/src/tasks/display_sensors_task.cpp +++ b/rover/src/tasks/display_sensors_task.cpp
@@ -22,23 +22,18 @@ #include <tasks/display_sensors_task.h> -#include <wiringPi.h> #include <unistd.h> #include <ctime> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> void *DisplaySensors_Task (void * arg) { timing display_sensors_task_tmr; - CollectThreadName("DisplaySensors_Task"); - display_sensors_task_tmr.setTaskID("Display-Sensors"); display_sensors_task_tmr.setDeadline(5.0); display_sensors_task_tmr.setPeriod(5.0);
diff --git a/rover/src/tasks/external_gpio_task.cpp b/rover/src/tasks/external_gpio_task.cpp index bf7f38e..87ce723 100644 --- a/rover/src/tasks/external_gpio_task.cpp +++ b/rover/src/tasks/external_gpio_task.cpp
@@ -16,26 +16,18 @@ #include <tasks/external_gpio_task.h> #include <ctime> -#include <wiringPi.h> -#include <softTone.h> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -void setupBuzzer (void) -{ - softToneCreate(BUZZER_PIN); -} - /* Checks global variable buzzer_status */ /* 1-> ON 0-> OFF */ void buzzerHandler (void) { + /* TODO: To be checked if ( buzzer_status_shared == 0 ) { softToneWrite (BUZZER_PIN, BUZZER_OFF_FREQ); @@ -54,56 +46,51 @@ { softToneWrite (BUZZER_PIN, BUZZER_OFF_FREQ); } - + */ } -void turnBuzzerOn (void) +void buttonHandler (void) { - pthread_mutex_lock(&buzzer_status_shared_lock); - buzzer_status_shared = 1; - pthread_mutex_unlock(&buzzer_status_shared_lock); -} +#ifndef DEBUG_WO_RSL + if (r.inRoverGpio().readShutdownButton() == LOW) + { + r.shutdown(); + } -void playShutdownTone (void) -{ - softToneWrite (BUZZER_PIN, BUZZER_SHUTDOWN_FREQ); - delay(2000); - softToneWrite (BUZZER_PIN, BUZZER_OFF_FREQ); -} + if (r.inRoverGpio().readUserButton() == LOW) + { + display_use_elsewhere_shared = 1; + r.sleep(500); -void playOnTone (void) -{ - softToneWrite (BUZZER_PIN, BUZZER_ON_FREQ); - delay(1000); - softToneWrite (BUZZER_PIN, BUZZER_OFF_FREQ); -} + //r.inRoverDisplay().initialize(); + r.inRoverDisplay().clearDisplay(); + r.inRoverDisplay().setTextSize(2); + r.inRoverDisplay().setTextColor(WHITE); -void turnBuzzerOff (void) -{ - pthread_mutex_lock(&buzzer_status_shared_lock); - buzzer_status_shared = 0; - pthread_mutex_unlock(&buzzer_status_shared_lock); -} + r.inRoverDisplay().setCursor(10,5); + r.inRoverDisplay().print("User"); + r.inRoverDisplay().setCursor(20,25); + r.inRoverDisplay().print("Button"); + r.inRoverDisplay().setCursor(30,45); + r.inRoverDisplay().print("Pressed"); -/* Simply shuts down the operating system, preferrably after - * OLED is done showing the indicator */ -void shutdownOS (void) -{ - system("halt"); + r.inRoverDisplay().display(); + + r.inRoverGpio().shutdownTone(); + + r.sleep(1000); + display_use_elsewhere_shared = 0; + } +#endif } void *External_GPIO_Task(void *arg) { timing extgpio_task_tmr; - CollectThreadName("External_GPIO_Task"); - extgpio_task_tmr.setTaskID("GPIO"); - extgpio_task_tmr.setDeadline(1); - extgpio_task_tmr.setPeriod(1); - - /* Setup Buzzer */ - setupBuzzer(); + extgpio_task_tmr.setDeadline(0.2); + extgpio_task_tmr.setPeriod(0.2); while (1) { @@ -114,6 +101,7 @@ /* Handle buzzer operation */ buzzerHandler(); + buttonHandler(); //Task content ends here -------------------------------------------------
diff --git a/rover/src/tasks/hono_interaction_task.cpp b/rover/src/tasks/hono_interaction_task.cpp index 0ce59ad..be9651c 100644 --- a/rover/src/tasks/hono_interaction_task.cpp +++ b/rover/src/tasks/hono_interaction_task.cpp
@@ -16,28 +16,20 @@ #include <tasks/hono_interaction_task.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <softPwm.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -#include <libraries/hono_interaction/hono_interaction.h> - void *Hono_Interaction_Task(void * arg) { timing hono_task_tmr; hono_task_tmr.setTaskID("HonoTsk"); - hono_task_tmr.setDeadline(1); - hono_task_tmr.setPeriod(1); - - CollectThreadName("Hono_Interaction_Task"); + hono_task_tmr.setDeadline(2); + hono_task_tmr.setPeriod(2); while (1) { @@ -48,17 +40,17 @@ // Send everything to Hono every second in this task using the following functions // TODO: This can be done with one curl command, probably a better way. - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverFront", distance_sr04_front_shared); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverFrontLeft",infrared_shared[3]); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverFrontRight", infrared_shared[2]); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverRear", distance_sr04_back_shared); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverRearLeft", infrared_shared[1]); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverRearRight", infrared_shared[0]); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverBearing", bearing_shared); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverUtilCpu1", cpu_util_shared[0]); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverUtilCpu2", cpu_util_shared[1]); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverUtilCpu3", cpu_util_shared[2]); - sendTelemetryDataToHonoInstance("idial.institute",8080,"DEFAULT_TENANT", "4711","roverUtilCpu4", cpu_util_shared[3]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverFront", distance_sr04_front_shared); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverFrontLeft",infrared_shared[3]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverFrontRight", infrared_shared[2]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverRear", distance_sr04_back_shared); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverRearLeft", infrared_shared[1]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverRearRight", infrared_shared[0]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverBearing", bearing_shared); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverUtilCpu1", cpu_util_shared[0]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverUtilCpu2", cpu_util_shared[1]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverUtilCpu3", cpu_util_shared[2]); + r.inRoverCloud().sendTelemetry("4711","sensor1","hono-secret","roverUtilCpu4", cpu_util_shared[3]); //Task content ends here -------------------------------------------------
diff --git a/rover/src/tasks/image_processing_task.cpp b/rover/src/tasks/image_processing_task.cpp index 4e9961f..f4931d3 100644 --- a/rover/src/tasks/image_processing_task.cpp +++ b/rover/src/tasks/image_processing_task.cpp
@@ -35,16 +35,11 @@ #include <tasks/image_processing_task.h> #include <ctime> -#include <wiringPi.h> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> -#include <roverapp.h> - #include <iostream> #include <fstream> @@ -56,6 +51,8 @@ #include <raspicam/raspicam.h> #include <raspicam/raspicam_cv.h> +#include <roverapp.h> + using namespace cv; using namespace std; @@ -63,8 +60,6 @@ { timing imgproc_task_tmr; - CollectThreadName("Image_Processing_Task"); - imgproc_task_tmr.setTaskID("ImgPr"); imgproc_task_tmr.setDeadline(1); imgproc_task_tmr.setPeriod(1);
diff --git a/rover/src/tasks/infrared_distance_task.cpp b/rover/src/tasks/infrared_distance_task.cpp index 4e5d5e5..6ca82c7 100644 --- a/rover/src/tasks/infrared_distance_task.cpp +++ b/rover/src/tasks/infrared_distance_task.cpp
@@ -24,57 +24,21 @@ #include <tasks/infrared_distance_task.h> #include <ctime> -#include <wiringPi.h> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <mcp3004.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -void setupInfraredSensors() -{ - // Init the analog digital converter - mcp3004Setup (BASE, SPI_CHAN); // 3004 and 3008 are the same 4/8 channels -} - -float getDistanceFromInfraredSensor(int channel){ - float x; - float y=analogRead (BASE+channel); - -// 1/cm to output voltage is almost linear between -// 80cm->0,4V->123 -// 6cm->3,1V->961 -// => y=5477*x+55 => x= (y-55)/5477 - if (y<123){ - x=100.00; - } else { - float inverse = (y-55)/5477; - //printf("inverse=%f\n",inverse); - // x is the distance in cm - x = 1/inverse; - } - - //printf("Distance channel row data %d:%f\n",channel,y); - //printf("Distance channel (cm) %d:%f\n",channel,x); - - return x; -} - void *InfraredDistance_Task (void * arg) { timing infrared_distance_task_tmr; - CollectThreadName("InfraredDistance_Task"); - infrared_distance_task_tmr.setTaskID("Infrared"); infrared_distance_task_tmr.setDeadline(0.5); infrared_distance_task_tmr.setPeriod(0.5); - //setupInfraredSensors(); int chan; while (1) @@ -87,7 +51,7 @@ pthread_mutex_lock(&infrared_lock); for (chan = 0; chan <= 3; chan ++) { - infrared_shared[chan] = getDistanceFromInfraredSensor(chan); + infrared_shared[chan] = r.inRoverSensors().readInfraredSensor(chan); } pthread_mutex_unlock(&infrared_lock); //Task content ends here -------------------------------------------------
diff --git a/rover/src/tasks/keycommand_task.cpp b/rover/src/tasks/keycommand_task.cpp index fe5c870..1e36b9a 100644 --- a/rover/src/tasks/keycommand_task.cpp +++ b/rover/src/tasks/keycommand_task.cpp
@@ -24,22 +24,17 @@ #include <ctime> #include <stdlib.h> -#include <wiringPi.h> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> void *KeyCommandInput_Task(void * arg) { timing keycommand_task_tmr; - CollectThreadName("KeyCommandInput_Task"); - keycommand_task_tmr.setTaskID("KeyCommand"); keycommand_task_tmr.setDeadline(0.2); keycommand_task_tmr.setPeriod(0.2);
diff --git a/rover/src/tasks/motordriver_task.cpp b/rover/src/tasks/motordriver_task.cpp index 0699def..6e6af7c 100644 --- a/rover/src/tasks/motordriver_task.cpp +++ b/rover/src/tasks/motordriver_task.cpp
@@ -22,25 +22,20 @@ */ #include <tasks/motordriver_task.h> -#include <tasks/oled_task.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <roverapp.h> -#include <softPwm.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> +#include <roverapp.h> void ExitAutomaticModes(void) { if (driving_mode == ACC || driving_mode == PARKING_LEFT || driving_mode == PARKING_RIGHT || driving_mode == BOOTH1 || driving_mode == BOOTH2) { - stop(); //Stop the rover first. + r.inRoverDriving().stopRover(); //Stop the rover first. pthread_mutex_lock(&driving_mode_lock); driving_mode = MANUAL; pthread_mutex_unlock(&driving_mode_lock); @@ -51,7 +46,7 @@ { if (driving_mode == ACC || driving_mode == PARKING_LEFT || driving_mode == PARKING_RIGHT || driving_mode == BOOTH1 || driving_mode == BOOTH2) { - stop(); //Stop the rover first. + r.inRoverDriving().stopRover(); //Stop the rover first. } pthread_mutex_lock(&driving_mode_lock); driving_mode = MANUAL; @@ -65,7 +60,7 @@ { if (driving_mode == ACC || driving_mode == MANUAL || driving_mode == BOOTH1 || driving_mode == BOOTH2) { - stop(); //Stop the rover first. + r.inRoverDriving().stopRover(); //Stop the rover first. } pthread_mutex_lock(&driving_mode_lock); driving_mode = PARKING_RIGHT; @@ -79,7 +74,7 @@ { if (driving_mode == ACC || driving_mode == MANUAL || driving_mode == BOOTH1 || driving_mode == BOOTH2) { - stop(); //Stop the rover first. + r.inRoverDriving().stopRover(); //Stop the rover first. } pthread_mutex_lock(&driving_mode_lock); driving_mode = PARKING_LEFT; @@ -93,7 +88,7 @@ { if (driving_mode == PARKING_LEFT || driving_mode == PARKING_RIGHT || driving_mode == MANUAL || driving_mode == BOOTH1 || driving_mode == BOOTH2 ) { - stop(); //Stop the rover first. + r.inRoverDriving().stopRover(); //Stop the rover first. } pthread_mutex_lock(&driving_mode_lock); driving_mode = ACC; @@ -107,7 +102,7 @@ { if (driving_mode == PARKING_LEFT || driving_mode == PARKING_RIGHT || driving_mode == MANUAL || driving_mode == BOOTH2 || driving_mode == ACC) { - stop(); //Stop the rover first. + r.inRoverDriving().stopRover(); //Stop the rover first. } pthread_mutex_lock(&driving_mode_lock); driving_mode = BOOTH1; @@ -121,7 +116,7 @@ { if (driving_mode == PARKING_LEFT || driving_mode == PARKING_RIGHT || driving_mode == MANUAL || driving_mode == BOOTH1 || driving_mode == ACC) { - stop(); //Stop the rover first. + r.inRoverDriving().stopRover(); //Stop the rover first. } pthread_mutex_lock(&driving_mode_lock); driving_mode = BOOTH2; @@ -136,19 +131,13 @@ { timing motordriver_task_tmr; - CollectThreadName("MotorDriver_Task"); - motordriver_task_tmr.setTaskID("MotorDriver"); motordriver_task_tmr.setDeadline(0.1); motordriver_task_tmr.setPeriod(0.1); - init(); int running = 1; char local_command = 'f'; - //runside (LEFT, BACKWARD, FULL_SPEED); - //runside (RIGHT, BACKWARD, FULL_SPEED); - while (running) { motordriver_task_tmr.recordStartTime(); @@ -173,42 +162,50 @@ break; case 'W': ExitAutomaticModes(); - go(FORWARD, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().goForward(); break; case 'D': ExitAutomaticModes(); - turn(BACKWARD, LEFT, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().turnBackwardRight(); break; case 'S': ExitAutomaticModes(); - go(BACKWARD, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().goBackward(); break; case 'A': ExitAutomaticModes(); - turn(BACKWARD, RIGHT, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().turnBackwardLeft(); break; case 'Q': ExitAutomaticModes(); - turn(FORWARD, RIGHT, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().turnForwardLeft(); break; case 'E': ExitAutomaticModes(); - turn(FORWARD, LEFT, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().turnForwardRight(); break; case 'K': //turn right on spot ExitAutomaticModes(); - turnOnSpot(FORWARD, RIGHT, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().turnRight(); break; case 'J': //turn left on spot ExitAutomaticModes(); - turnOnSpot(FORWARD, LEFT, speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().turnLeft(); break; case 'U': //Calibration mode break; case 'R': //Shutdown hook from web server - shutdownOSwithDisplay(); + r.shutdown(); break; case 'M': //ACC mode set @@ -227,7 +224,7 @@ BoothMode2Set(); break; case 'F': - stop(); + r.inRoverDriving().stopRover(); break; } //Task content ends here -------------------------------------------------
diff --git a/rover/src/tasks/oled_task.cpp b/rover/src/tasks/oled_task.cpp index 4aa4307..4f0d6ef 100644 --- a/rover/src/tasks/oled_task.cpp +++ b/rover/src/tasks/oled_task.cpp
@@ -40,82 +40,18 @@ */ #include <tasks/oled_task.h> -#include <tasks/external_gpio_task.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <roverapp.h> - -#include <libraries/pthread_monitoring/collect_thread_name.h> - -#include <drivers/oled_drivers/ArduiPi_SSD1306.h> -#include <drivers/oled_drivers/Adafruit_GFX.h> -#include <drivers/oled_drivers/Adafruit_SSD1306.h> +#include <signal.h> /* APPSTACLE Project logo */ #include "../drivers/oled_drivers/appstacle_logo.c" -#include <libraries/status_library/status_library.h> - -Adafruit_SSD1306 display; - -/* Config Option */ -struct s_opts -{ - int oled; - int verbose; -} ; - -/* default options values */ -s_opts opts = { - OLED_ADAFRUIT_I2C_128x64, // Default oled - false // Not verbose -}; - -void OLED_Setup (void) -{ - /* I2C change parameters to fit to your LCD */ - if ( !display.init(OLED_I2C_RESET,opts.oled) ) - exit(EXIT_FAILURE); - - display.begin(); - display.clearDisplay(); // clears the screen and buffer -} - -/* Proper shutdown function, including showing message in the OLED display */ -void shutdownOSwithDisplay(void) -{ - /* Prepare "Shutting Down..." */ - display.clearDisplay(); - - display.setTextSize(2); - display.setTextColor(WHITE); - - display.setCursor(20,10); - display.print("Shutting"); - - display.setTextColor(WHITE); - - display.setCursor(20,32); - display.print("Down..."); - - /* Display everything earlier this time*/ - display.display(); - - /* Play the shutdown tone..*/ - playShutdownTone(); - - /* Here we're shutting Raspberry Pi down.. */ - shutdownOS(); - - /* Abort the application for safety reasons */ - abort(); -} +#include <roverapp.h> void *OLED_Task (void * arg) { @@ -124,11 +60,9 @@ oled_task_tmr.setDeadline(0.5); oled_task_tmr.setPeriod(0.5); - CollectThreadName("OLED_Task"); - int counter_500ms = 0; - OLED_Setup(); + RoverDisplay my_display = r.inRoverDisplay(); while (1) { @@ -139,194 +73,208 @@ if ( shutdown_hook_shared == 0) { - /* Our internal control-timer actions */ - switch (counter_500ms) + /* If the display is not in use somewhere else asynchronously */ + if (display_use_elsewhere_shared == 0) { - /* If counter hits counter_500ms * 0.5 sec */ - /* Display APPSTACLE logo in between */ - case 0: - case 5: - case 10: - case 15: - case 20: - /* Prepare APPSTACLE logo*/ - display.clearDisplay(); - /* Black logo */ - //display.fillRect (0, 0, 128, 64, WHITE); - //display.drawBitmap (0, 0, appstacle_logo, 128, 64, BLACK); + /* Our internal control-timer actions */ + switch (counter_500ms) + { + /* If counter hits counter_500ms * 0.5 sec */ + /* Display APPSTACLE logo in between */ + case 0: + case 5: + case 10: + case 15: + case 20: + /* Prepare APPSTACLE logo*/ + my_display.clearDisplay(); - /* White logo */ - display.drawBitmap (0, 0, appstacle_logo, 128, 64, WHITE); + /* Black logo */ + //my_display.fillRect (0, 0, 128, 64, WHITE); + //my_display.drawBitmap (0, 0, appstacle_logo, 128, 64, BLACK); - break; + /* White logo */ + my_display.drawBitmap (0, 0, appstacle_logo, 128, 64, WHITE); - case 1: /* If counter hits counter_500ms * 0.5 sec */ - /* Prepare WLAN availability */ - display.clearDisplay(); + break; - //display.drawRect(0, 0, display.width(), display.height(), WHITE); - //display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); + case 1: /* If counter hits counter_500ms * 0.5 sec */ + /* Prepare WLAN availability */ + my_display.clearDisplay(); - display.setTextSize(2); - display.setTextColor(WHITE); + //my_display.drawRect(0, 0, display.width(), display.height(), WHITE); + //my_display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); - display.setCursor(45,10); - display.print("WLAN:"); + my_display.setTextSize(2); + my_display.setTextColor(WHITE); - display.setTextSize(3); - display.setTextColor(WHITE); + my_display.setCursor(45,10); + my_display.print("WLAN:"); - if (retrieveWLANStatus() == 1) - { - display.setCursor(50,32); - display.print("ON"); - } - else - { - display.setCursor(43,32); - display.print("OFF"); - } + my_display.setTextSize(3); + my_display.setTextColor(WHITE); - break; + if (r.inRoverUtils().getWlanStatus() == 1) + { + my_display.setCursor(50,32); + my_display.print("ON"); + } + else + { + my_display.setCursor(43,32); + my_display.print("OFF"); + } - case 6: /* If counter hits counter_500ms * 0.5 sec */ - /* Prepare Ethernet availability*/ - display.clearDisplay(); + break; - //display.drawRect(0, 0, display.width(), display.height(), WHITE); - //display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); + case 6: /* If counter hits counter_500ms * 0.5 sec */ + /* Prepare Ethernet availability*/ + my_display.clearDisplay(); - display.setTextSize(2); - display.setTextColor(WHITE); + //my_display.drawRect(0, 0, display.width(), display.height(), WHITE); + //my_display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); - display.setCursor(48,10); - display.print("ETH:"); + my_display.setTextSize(2); + my_display.setTextColor(WHITE); - display.setTextSize(3); - display.setTextColor(WHITE); + my_display.setCursor(48,10); + my_display.print("ETH:"); - if (retrieveETHStatus() == 1) - { - display.setCursor(50,32); - display.print("ON"); - } - else - { - display.setCursor(43,32); - display.print("OFF"); - } + my_display.setTextSize(3); + my_display.setTextColor(WHITE); - break; + if (r.inRoverUtils().getEthernetStatus() == 1) + { + my_display.setCursor(50,32); + my_display.print("ON"); + } + else + { + my_display.setCursor(43,32); + my_display.print("OFF"); + } - case 11: /* If counter hits counter_500ms * 0.5 sec */ - /* Prepare Internet availability */ - display.clearDisplay(); + break; - //display.drawRect(0, 0, display.width(), display.height(), WHITE); - //display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); + case 11: /* If counter hits counter_500ms * 0.5 sec */ + /* Prepare Internet availability */ + my_display.clearDisplay(); - display.setTextSize(2); - display.setTextColor(WHITE); + //my_display.drawRect(0, 0, display.width(), display.height(), WHITE); + //my_display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); - display.setCursor(12,10); - display.print("INTERNET:"); + my_display.setTextSize(2); + my_display.setTextColor(WHITE); - display.setTextSize(3); - display.setTextColor(WHITE); + my_display.setCursor(12,10); + my_display.print("INTERNET:"); - if (retrieveINTERNETStatus() == 1) - { - display.setCursor(50,32); - display.print("ON"); - } - else - { - display.setCursor(43,32); - display.print("OFF"); - } + my_display.setTextSize(3); + my_display.setTextColor(WHITE); - break; + if (r.inRoverUtils().getInternetStatus() == 1) + { + my_display.setCursor(50,32); + my_display.print("ON"); + } + else + { + my_display.setCursor(43,32); + my_display.print("OFF"); + } - case 16: /* If counter hits counter_500ms * 0.5 sec */ - /* Prepare Bluetooth availability */ - display.clearDisplay(); + break; - //display.drawRect(0, 0, display.width(), display.height(), WHITE); - //display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); + case 16: /* If counter hits counter_500ms * 0.5 sec */ + /* Prepare Bluetooth availability */ + my_display.clearDisplay(); - display.setTextSize(2); - display.setTextColor(WHITE); + //my_display.drawRect(0, 0, display.width(), display.height(), WHITE); + //my_display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); - display.setCursor(8,10); - display.print("BLUETOOTH:"); + my_display.setTextSize(2); + my_display.setTextColor(WHITE); - display.setTextSize(3); - display.setTextColor(WHITE); + my_display.setCursor(8,10); + my_display.print("BLUETOOTH:"); - if (retrieveBLUETOOTHStatus() == 1) - { - display.setCursor(50,32); - display.print("ON"); - } - else - { - display.setCursor(43,32); - display.print("OFF"); - } + my_display.setTextSize(3); + my_display.setTextColor(WHITE); - break; + if (r.inRoverUtils().getBluetoothStatus() == 1) + { + my_display.setCursor(50,32); + my_display.print("ON"); + } + else + { + my_display.setCursor(43,32); + my_display.print("OFF"); + } - case 21: /* If counter hits counter_500ms * 0.5 sec */ - /* Prepare Hono Instance (Cloud) availability */ - display.clearDisplay(); + break; - //display.drawRect(0, 0, display.width(), display.height(), WHITE); - //display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); + case 21: /* If counter hits counter_500ms * 0.5 sec */ + /* Prepare Hono Instance (Cloud) availability */ + my_display.clearDisplay(); - display.setTextSize(2); - display.setTextColor(WHITE); + //my_display.drawRect(0, 0, display.width(), display.height(), WHITE); + //my_display.drawRect(2, 2, display.width()-4, display.height()-4, WHITE); - display.setCursor(45,10); - display.print("HONO:"); + my_display.setTextSize(2); + my_display.setTextColor(WHITE); - display.setTextSize(3); - display.setTextColor(WHITE); + my_display.setCursor(45,10); + my_display.print("HONO:"); - if (retrieveHONOStatus() == 1) - { - display.setCursor(50,32); - display.print("ON"); - } - else - { - display.setCursor(43,32); - display.print("OFF"); - } + my_display.setTextSize(3); + my_display.setTextColor(WHITE); - break; + if (r.inRoverUtils().getHonoCloudStatus("idial.institute",8080,"DEFAULT_TENANT", "4711","sensor1","hono-secret") == 1) + { + my_display.setCursor(50,32); + my_display.print("ON"); + } + else + { + my_display.setCursor(43,32); + my_display.print("OFF"); + } - default: /* None of the above */ - // Wait - break; + break; - } /* switch-end */ + default: /* None of the above */ + // Wait + break; + + } /* switch-end */ + + } /* if display_use_elsewhere_shared */ + else + { + + } } else { // Proper shutdown function, including showing message in the OLED display - shutdownOSwithDisplay(); + r.shutdown(); } - /* Display the stuff NOW */ - display.display(); + /* If the display is not in use somewhere else asynchronously */ + if (display_use_elsewhere_shared == 0) + { + /* Display the stuff NOW */ + my_display.display(); - /* Increment the counter */ - counter_500ms += 1; + /* Increment the counter */ + counter_500ms += 1; - /* Since only first 25*0.5 seconds we do something, we can clear the variable */ - if (counter_500ms > 25) - counter_500ms = 0; + /* Since only first 25*0.5 seconds we do something, we can clear the variable */ + if (counter_500ms > 25) + counter_500ms = 0; + } //Task content ends here -------------------------------------------------
diff --git a/rover/src/tasks/parking_task.cpp b/rover/src/tasks/parking_task.cpp index 87eb56f..e9b2588 100644 --- a/rover/src/tasks/parking_task.cpp +++ b/rover/src/tasks/parking_task.cpp
@@ -19,27 +19,17 @@ #include <tasks/parking_task.h> -#include <wiringPi.h> #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <roverapp.h> -#include <softPwm.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> -#include <tasks/motordriver_task.h> +#include <roverapp.h> int StopParking (void) { - stop(); - //Write to text file .. - ofstream myfile; - myfile.open("/var/www/html/ROVER_CMD.inc"); - myfile << "F"; - myfile.close(); + r.inRoverDriving().stopRover(); pthread_mutex_lock(&driving_mode_lock); driving_mode = MANUAL; pthread_mutex_unlock(&driving_mode_lock); @@ -53,8 +43,6 @@ parking_task_tmr.setDeadline(0.1); parking_task_tmr.setPeriod(0.1); - CollectThreadName("Parking_Task"); - float bearing_begin; while (1) @@ -66,7 +54,8 @@ if (driving_mode == PARKING_LEFT) { bearing_begin = bearing_shared; - turnOnSpot(FORWARD, LEFT, speed_shared-50); + r.inRoverDriving().setSpeed(speed_shared-50); + r.inRoverDriving().turnLeft(); /** * The following bearing based parking does currently not work due to very unreliable bearing values */ @@ -84,34 +73,39 @@ delay(3000); - stop(); - go(FORWARD,speed_shared); + r.inRoverDriving().stopRover(); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().goForward(); delay(2000); - stop(); + r.inRoverDriving().stopRover(); //bearing_begin = bearing_shared; - turnOnSpot(FORWARD, RIGHT, speed_shared-50); + r.inRoverDriving().setSpeed(speed_shared-50); + r.inRoverDriving().turnRight(); //while(((int)bearing_begin+(int)bearing_shared) % 360 <80); delay(3000); - stop(); + r.inRoverDriving().stopRover(); StopParking(); } else if (driving_mode == PARKING_RIGHT) { bearing_begin = bearing_shared; - turnOnSpot(FORWARD, RIGHT, speed_shared-50); + r.inRoverDriving().setSpeed(speed_shared-50); + r.inRoverDriving().turnRight(); //while(((int)bearing_begin+(int)bearing_shared) % 360 <85); delay(3000); - go(FORWARD,speed_shared); + r.inRoverDriving().setSpeed(speed_shared); + r.inRoverDriving().goForward(); delay(2000); bearing_begin = bearing_shared; - turnOnSpot(FORWARD, LEFT, speed_shared-50); + r.inRoverDriving().setSpeed(speed_shared-50); + r.inRoverDriving().turnLeft(); delay(3000); - stop(); + r.inRoverDriving().stopRover(); StopParking(); }
diff --git a/rover/src/tasks/record_timing_task.cpp b/rover/src/tasks/record_timing_task.cpp index 58da7f9..54f4c7b 100644 --- a/rover/src/tasks/record_timing_task.cpp +++ b/rover/src/tasks/record_timing_task.cpp
@@ -21,15 +21,12 @@ #include <tasks/record_timing_task.h> -#include <wiringPi.h> #include <unistd.h> #include <ctime> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> @@ -62,8 +59,6 @@ { timing record_timing_task_tmr; - CollectThreadName("Record_Timing_Task"); - record_timing_task_tmr.setTaskID("RecordTiming"); record_timing_task_tmr.setDeadline(0.5); record_timing_task_tmr.setPeriod(2.0);
diff --git a/rover/src/tasks/socket_client_task.cpp b/rover/src/tasks/socket_client_task.cpp index 7775c3a..8b3bdf8 100644 --- a/rover/src/tasks/socket_client_task.cpp +++ b/rover/src/tasks/socket_client_task.cpp
@@ -15,17 +15,12 @@ #include <tasks/socket_client_task.h> -#include <wiringPi.h> #include <unistd.h> #include <ctime> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> -#include <roverapp.h> - #include <unistd.h> #include <string.h> @@ -40,6 +35,8 @@ #include <math.h> +#include <roverapp.h> + /* Global definitions */ int roverapp_send_sockfd; @@ -93,11 +90,9 @@ { timing socket_client_task_tmr; - CollectThreadName("Socket_Client_Task"); - socket_client_task_tmr.setTaskID("Socket_Client_Task"); - socket_client_task_tmr.setDeadline(0.8); - socket_client_task_tmr.setPeriod(0.8); + socket_client_task_tmr.setDeadline(0.5); + socket_client_task_tmr.setPeriod(0.5); /* Add termination signal handler to properly close socket */ signal(SIGINT, Socket_Client_Task_Terminator);
diff --git a/rover/src/tasks/socket_server_task.cpp b/rover/src/tasks/socket_server_task.cpp index 33ddd77..d2f2dfc 100644 --- a/rover/src/tasks/socket_server_task.cpp +++ b/rover/src/tasks/socket_server_task.cpp
@@ -17,18 +17,11 @@ #include <string.h> #include <ctime> -#include <wiringPi.h> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <softPwm.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> -#include <roverapp.h> - -/* Signal header */ #include <signal.h> /* Socket defs header */ @@ -37,6 +30,8 @@ /* json-cpp library */ #include <json/json.h> +#include <roverapp.h> + /* Global definitions */ int roverapp_listen_sockfd; int newroverapp_listen_sockfd; @@ -96,8 +91,6 @@ { timing socket_server_task_tmr; - CollectThreadName("Socket_Server_Task"); - socket_server_task_tmr.setTaskID("Socket_Server_Task"); socket_server_task_tmr.setDeadline(0.05); socket_server_task_tmr.setPeriod(0.05);
diff --git a/rover/src/tasks/srf02_task.cpp b/rover/src/tasks/srf02_task.cpp index e97b064..91d2bd5 100644 --- a/rover/src/tasks/srf02_task.cpp +++ b/rover/src/tasks/srf02_task.cpp
@@ -19,13 +19,9 @@ #include <ctime> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> -#include <roverapp.h> - #include <linux/i2c-dev.h> #include <fcntl.h> #include <string.h> @@ -35,6 +31,9 @@ #include <sys/types.h> #include <sys/stat.h> +#include <roverapp.h> +#include <roverapi/basic_psys_rover.h> + /* Name of the I2C device we will be using */ /* For older raspberry pi modules use "/dev/i2c-0" instead of "/dev/i2c-1" for the i2c port */ @@ -125,8 +124,6 @@ srf02_task_tmr.setDeadline(1); srf02_task_tmr.setPeriod(1); - CollectThreadName("SRF02_Task"); - unsigned int front_sensor, rear_sensor; while (1)
diff --git a/rover/src/tasks/temperature_task.cpp b/rover/src/tasks/temperature_task.cpp index f474700..1063535 100644 --- a/rover/src/tasks/temperature_task.cpp +++ b/rover/src/tasks/temperature_task.cpp
@@ -23,108 +23,23 @@ #include <tasks/temperature_task.h> #include <ctime> -#include <wiringPi.h> -#include <wiringPiI2C.h> #include <unistd.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -void readDHT22SensorData() -{ - int data[5] = { 0, 0, 0, 0, 0 }; - - uint8_t laststate = HIGH; - uint8_t counter = 0; - uint8_t j = 0, i; - - data[0] = data[1] = data[2] = data[3] = data[4] = 0; - - /* pull pin down for 18 milliseconds */ - pinMode( DHT22_RPI_PIN, OUTPUT ); - digitalWrite( DHT22_RPI_PIN, LOW ); - delay( 18 ); - - /* prepare to read the pin */ - pinMode( DHT22_RPI_PIN, INPUT ); - - /* detect change and read data */ - for ( i = 0; i < MAX_TIMINGS; i++ ) - { - counter = 0; - while ( digitalRead( DHT22_RPI_PIN ) == laststate ) - { - counter++; - delayMicroseconds( 1 ); - if ( counter == 255 ) - { - break; - } - } - laststate = digitalRead( DHT22_RPI_PIN ); - - if ( counter == 255 ) - break; - - /* ignore first 3 transitions */ - if ( (i >= 4) && (i % 2 == 0) ) - { - /* shove each bit into the storage bytes */ - data[j / 8] <<= 1; - if ( counter > 16 ) - data[j / 8] |= 1; - j++; - } - } - - /* - * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte - * print it out if data is good - */ - if ( (j >= 40) && - (data[4] == ( (data[0] + data[1] + data[2] + data[3]) & 0xFF) ) ) - { - float h = (float)((data[0] << 8) + data[1]) / 10; - if ( h > 100 ) - { - h = data[0]; // for DHT11 - } - float c = (float)(((data[2] & 0x7F) << 8) + data[3]) / 10; - if ( c > 125 ) - { - c = data[2]; // for DHT11 - } - if ( data[2] & 0x80 ) - { - c = -c; - } - float f = c * 1.8f + 32; - //printf( "Humidity = %.1f %% Temperature = %.1f *C (%.1f *F)\n", h, c, f ); - - pthread_mutex_lock(&temperature_lock); - temperature_shared = c; - pthread_mutex_unlock(&temperature_lock); - - pthread_mutex_lock(&humidity_lock); - humidity_shared = h; - pthread_mutex_unlock(&humidity_lock); - } -} - void *Temperature_Task(void *arg) { timing temperature_task_tmr; - CollectThreadName("Temperature_Task"); - temperature_task_tmr.setTaskID("DHT22"); temperature_task_tmr.setDeadline(0.5); temperature_task_tmr.setPeriod(0.5); + float temperature, humidity; + while (1) { temperature_task_tmr.recordStartTime(); @@ -132,7 +47,16 @@ //Task content starts here ----------------------------------------------- - readDHT22SensorData(); + temperature = r.inRoverSensors().readTemperature(); + humidity = r.inRoverSensors().readHumidity(); + + pthread_mutex_lock(&temperature_lock); + temperature_shared = temperature; + pthread_mutex_unlock(&temperature_lock); + + pthread_mutex_lock(&humidity_lock); + humidity_shared = humidity; + pthread_mutex_unlock(&humidity_lock); //Task content ends here -------------------------------------------------
diff --git a/rover/src/tasks/ultrasonic_sensor_grove_task.cpp b/rover/src/tasks/ultrasonic_sensor_grove_task.cpp index b14a441..f97f4be 100644 --- a/rover/src/tasks/ultrasonic_sensor_grove_task.cpp +++ b/rover/src/tasks/ultrasonic_sensor_grove_task.cpp
@@ -25,62 +25,23 @@ #include <tasks/ultrasonic_sensor_grove_task.h> -#include <wiringPi.h> #include <ctime> #include <pthread.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -void setup_GrooveUltrasonicRanger() { - //wiringPiSetup(); //Since this can only be used once in a program, we do it in main and comment this. - -} - -int getCM_GrooveUltrasonicRanger() -{ - long startTime, stopTime, elapsedTime, distance = 0; - pinMode(SIG, OUTPUT); - digitalWrite(SIG, LOW); - delayMicroseconds(2); - digitalWrite(SIG, HIGH); - delayMicroseconds(5); - digitalWrite(SIG,LOW); - pinMode(SIG,INPUT); - - startTime = micros(); - while (digitalRead(SIG) == LOW ); - startTime = micros(); - // For values above 40cm, groove sensor is unable to receive signals which causes it to stuck - // This is resolved by adding the timeout below. - // However, this timeout cause values bigger than 40 to fluctuate - while (digitalRead(SIG) == HIGH && micros() < startTime + 100000); - stopTime = micros(); - elapsedTime = stopTime - startTime; - distance = elapsedTime / 29 /2; - // The below protection is to ensure there is no value fluctuation - if (distance > 40 ) - distance = 40; - return distance; -} - - void *Ultrasonic_Sensor_Grove_Task(void *unused) { timing ultrasonic_grove_task_tmr; - CollectThreadName("Ultrasonic_Sensor_Grove_Task"); - ultrasonic_grove_task_tmr.setTaskID("GrooveUltrasonic"); ultrasonic_grove_task_tmr.setDeadline(0.5); ultrasonic_grove_task_tmr.setPeriod(0.5); - setup_GrooveUltrasonicRanger(); while (1) { ultrasonic_grove_task_tmr.recordStartTime(); @@ -91,7 +52,7 @@ distance_grove_shared = getCM_GrooveUltrasonicRanger(); pthread_mutex_unlock(&distance_grove_lock);*/ pthread_mutex_lock(&distance_sr04_back_lock); - distance_sr04_back_shared = getCM_GrooveUltrasonicRanger(); + distance_sr04_back_shared = r.inRoverSensors().readGrooveUltrasonicSensor(r.inRoverSensors().ROVER_REAR); pthread_mutex_unlock(&distance_sr04_back_lock); //printf("Distance: %dcm\n", getCM_GrooveUltrasonicRanger()); //Task content ends here -------------------------------------------------
diff --git a/rover/src/tasks/ultrasonic_sensor_sr04_back_task.cpp b/rover/src/tasks/ultrasonic_sensor_sr04_back_task.cpp index 1828f89..12ef99b 100644 --- a/rover/src/tasks/ultrasonic_sensor_sr04_back_task.cpp +++ b/rover/src/tasks/ultrasonic_sensor_sr04_back_task.cpp
@@ -44,69 +44,23 @@ #include <tasks/ultrasonic_sensor_sr04_back_task.h> -#include <wiringPi.h> #include <ctime> #include <pthread.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -void setup_HCSR04UltrasonicBack() { - //wiringPiSetup(); - pinMode(TRIG1, OUTPUT); - pinMode(ECHO1, INPUT); - - //TRIG pin must start LOW - digitalWrite(TRIG1, LOW); - delayMicroseconds(2); -} - -int getCM_HCSR04UltrasonicBack() { - int distance = 0; - //Send trig pulse - digitalWrite(TRIG1, HIGH); - delayMicroseconds(10); - digitalWrite(TRIG1, LOW); -// printf("x\n"); - - //Wait for echo start - long startTime = micros(); - while(digitalRead(ECHO1) == LOW && micros() < startTime + 100000); - - //Wait for echo end - startTime = micros(); - while(digitalRead(ECHO1) == HIGH); - long travelTime = micros() - startTime; - - //Get distance in cm - distance = travelTime * 34300; - distance = distance / 1000000; - distance = distance / 2; - // The below protection is to ensure there is no value fluctuation due to timeout - if (distance > 40 ) - distance = 40; -// printf("dist=%d\n",distance); - - return distance; -} - - -void *Ultrasonic_Sensor_SR04_Back_Task(void *unused) +void *Ultrasonic_Sensor_SR04_Back_Task (void *unused) { timing ultrasonic_sr04_back_task_tmr; - CollectThreadName("Ultrasonic_Sensor_SR04_Back_Task"); - ultrasonic_sr04_back_task_tmr.setTaskID("Ultrasonic_SR04_Back"); ultrasonic_sr04_back_task_tmr.setDeadline(0.1); ultrasonic_sr04_back_task_tmr.setPeriod(0.1); - setup_HCSR04UltrasonicBack(); while (1) { ultrasonic_sr04_back_task_tmr.recordStartTime(); @@ -114,12 +68,10 @@ //Task content starts here ----------------------------------------------- pthread_mutex_lock(&distance_sr04_back_lock); - distance_sr04_back_shared = getCM_HCSR04UltrasonicBack(); + distance_sr04_back_shared = r.inRoverSensors().readHCSR04UltrasonicSensor(r.inRoverSensors().ROVER_REAR); pthread_mutex_unlock(&distance_sr04_back_lock); - //printf("Distance: %dcm\n", getCM_GrooveUltrasonicRanger()); //Task content ends here ------------------------------------------------- - ultrasonic_sr04_back_task_tmr.recordEndTime(); //!!! ultrasonic_sr04_back_task_tmr.calculateExecutionTime(); ultrasonic_sr04_back_task_tmr.calculateDeadlineMissPercentage();
diff --git a/rover/src/tasks/ultrasonic_sensor_sr04_front_task.cpp b/rover/src/tasks/ultrasonic_sensor_sr04_front_task.cpp index 2140944..7329ce5 100644 --- a/rover/src/tasks/ultrasonic_sensor_sr04_front_task.cpp +++ b/rover/src/tasks/ultrasonic_sensor_sr04_front_task.cpp
@@ -44,68 +44,23 @@ #include <tasks/ultrasonic_sensor_sr04_front_task.h> -#include <wiringPi.h> #include <ctime> #include <pthread.h> #include <libraries/timing/timing.h> -#include <api/basic_psys_rover.h> #include <interfaces.h> #include <pthread.h> -#include <libraries/pthread_monitoring/collect_thread_name.h> #include <roverapp.h> -void setup_HCSR04UltrasonicFront() { - //wiringPiSetup(); - pinMode(TRIG0, OUTPUT); - pinMode(ECHO0, INPUT); - - //TRIG pin must start LOW - digitalWrite(TRIG0, LOW); - delayMicroseconds(2); -} - -int getCM_HCSR04UltrasonicFront() { - int distance = 0; - //Send trig pulse - digitalWrite(TRIG0, HIGH); - delayMicroseconds(10); - digitalWrite(TRIG0, LOW); -// printf("x\n"); - - //Wait for echo start - long startTime = micros(); - while(digitalRead(ECHO0) == LOW && micros() < startTime + 100000); - - //Wait for echo end - startTime = micros(); - while(digitalRead(ECHO0) == HIGH); - long travelTime = micros() - startTime; - - //Get distance in cm - distance = travelTime * 34300; - distance = distance / 1000000; - distance = distance / 2; - // The below protection is to ensure there is no value fluctuation due to timeout - if (distance > 40 ) - distance = 40; -// printf("dist=%d\n",distance); - return distance; -} - - void *Ultrasonic_Sensor_SR04_Front_Task(void *unused) { timing ultrasonic_sr04_front_task_tmr; - CollectThreadName("Ultrasonic_Sensor_SR04_Front_Task"); - ultrasonic_sr04_front_task_tmr.setTaskID("Ultrasonic_SR04_Front"); ultrasonic_sr04_front_task_tmr.setDeadline(0.1); ultrasonic_sr04_front_task_tmr.setPeriod(0.1); - setup_HCSR04UltrasonicFront(); while (1) { ultrasonic_sr04_front_task_tmr.recordStartTime(); @@ -113,9 +68,8 @@ //Task content starts here ----------------------------------------------- pthread_mutex_lock(&distance_sr04_front_lock); - distance_sr04_front_shared = getCM_HCSR04UltrasonicFront(); + distance_sr04_front_shared = r.inRoverSensors().readHCSR04UltrasonicSensor(r.inRoverSensors().ROVER_FRONT); pthread_mutex_unlock(&distance_sr04_front_lock); - //printf("Distance: %dcm\n", getCM_GrooveUltrasonicRanger()); //Task content ends here ------------------------------------------------- ultrasonic_sr04_front_task_tmr.recordEndTime();