00001 #include "platform_communication.h"
00002
00003 const int BAUD = 19200, POS_TRUE = 1, CNT = 4;
00004
00005
00006
00007 static short serial_in_pin = 10, ready_to_send_pin = 11, ready_to_receive_pin = 12;
00008
00009
00010 static short steering_recommendation = 0, throttle_recommendation = 0;
00011 static short auto_avoid_obstacle = 0, radio_control_mode = 0;
00012 static char in_list[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
00013
00014 int initializePlatformCommunication(int serial_in_pin, int data_ready_pin, int ack_pin) {
00015
00016 serial_in_pin = serial_in_pin;
00017 ready_to_send_pin = data_ready_pin;
00018 ready_to_receive_pin = ack_pin;
00019 INPUT(serial_in_pin);
00020 INPUT(ready_to_send_pin);
00021 OUTPUT(ready_to_receive_pin);
00022 HIGH(ready_to_receive_pin);
00023 WAIT(1);
00024 if(!IN(ready_to_receive_pin)) {
00025 INPUT(ready_to_receive_pin);
00026 return -1;
00027 } else { return 0; }
00028 }
00029
00030
00031 int checkForPlatformData() {
00032
00033 if(!IN(ready_to_send_pin)) {
00034
00035 LOW(ready_to_receive_pin);
00036
00037
00038 SERIN(serial_in_pin, BAUD, POS_TRUE, CNT, in_list);
00039
00040 steering_recommendation = in_list[0];
00041 throttle_recommendation = in_list[1];
00042 auto_avoid_obstacle = in_list[2];
00043 radio_control_mode = in_list[3];
00044 HIGH(ready_to_receive_pin);
00045 return 1;
00046 } else { return 0; }
00047 }
00048
00049 short getSteeringRecommendation() {
00050 if(steering_recommendation > 127) {
00051 steering_recommendation = steering_recommendation - 256;
00052 }
00053 return ceilf(3.19 * (float)steering_recommendation);
00054 }
00055
00056 short getThrottleRecommendation() {
00057 if(throttle_recommendation > 127) {
00058 throttle_recommendation = throttle_recommendation - 256;
00059 }
00060 return ceilf(3.19 * (float)throttle_recommendation);
00061 }
00062
00063 short getAutoAvoidObstacle() {
00064 return auto_avoid_obstacle;
00065 }
00066
00067 short getRadioControlMode() {
00068 return radio_control_mode;
00069 }
00070
00071