From b96235a293cbd26ee337c9ce4e86bff2ab14bd72 Mon Sep 17 00:00:00 2001 From: Erick Sanchez Date: Sat, 31 Dec 2016 12:26:57 -0800 Subject: [PATCH 1/3] init SensorArray class --- SensorArray.cpp | 31 +++++++++++++++++++++++++++++++ SensorArray.h | 12 ++++++++++++ line-follower.vcxproj | 6 +++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 SensorArray.cpp create mode 100644 SensorArray.h diff --git a/SensorArray.cpp b/SensorArray.cpp new file mode 100644 index 0000000..bfca1e4 --- /dev/null +++ b/SensorArray.cpp @@ -0,0 +1,31 @@ +#include "SensorArray.h" + +#ifndef _SENSOR_ARRAY_h +#define _SENSOR_ARRAY_h +#endif + +#if defined(ARDUINO) && ARDUINO >= 100 +#include "arduino.h" +#else +#include "WProgram.h" +#endif + + +SensorArray::SensorArray() +{ +} + +SensorArray::SensorArray(int pins[], int nPins) +{ +} + + +SensorArray::~SensorArray() +{ +} + + +double SensorArray::error() +{ + return 0; +} diff --git a/SensorArray.h b/SensorArray.h new file mode 100644 index 0000000..c914671 --- /dev/null +++ b/SensorArray.h @@ -0,0 +1,12 @@ +#pragma once + +class SensorArray +{ + int N_SENSORS; +public: + SensorArray(); + SensorArray(int pins[], int nPins); + ~SensorArray(); + double error(); +}; + diff --git a/line-follower.vcxproj b/line-follower.vcxproj index 7648ada..2948fe6 100644 --- a/line-follower.vcxproj +++ b/line-follower.vcxproj @@ -47,7 +47,7 @@ Level3 Disabled true - C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\libraries;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\libraries;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\projects\libraries;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\cores\teensy3;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\cores\teensy3\avr;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\cores\teensy3\util;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\cores\teensy3\utils;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\cores\teensy3\avr;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\tools\avr/../arm/bin/..\arm-none-eabi\include;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\projects\line-follower;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\cores\teensy3;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\aif2jys0.atj\Micro Platforms\default\debuggers\VM_DBG;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\libraries;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\arduino-1.6.7\hardware\teensy\avr\libraries;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\aif2jys0.atj\Micro Platforms\default\debuggers;C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\projects\libraries;%(AdditionalIncludeDirectories) + C:\Users\ericksanc\Documents\GitHub\arduino-1.6.12\libraries;C:\Users\ericksanc\Documents\GitHub\arduino-1.6.12\hardware\arduino\avr\libraries;C:\Users\ericksanc\Documents\Arduino\libraries;C:\Users\ericksanc\Documents\GitHub\arduino-1.6.12\hardware\arduino\avr\cores\arduino;C:\Users\ericksanc\Documents\GitHub\arduino-1.6.12\hardware\arduino\avr\variants\yun;C:\Users\ericksanc\Documents\GitHub\line-follower;C:\Users\ericksanc\Documents\GitHub\arduino-1.6.12\hardware\tools\avr/avr/include/;C:\Users\ericksanc\Documents\GitHub\arduino-1.6.12\hardware\tools\avr//avr/include/avr/;C:\Users\ericksanc\Documents\GitHub\arduino-1.6.12\hardware\tools\avr/lib\gcc\avr\4.8.1\include;%(AdditionalIncludeDirectories) C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\projects\line-follower\__vm\.line-follower.vsarduino.h;%(ForcedIncludeFiles) false __HARDWARE_MK20dx256__;__HARDWARE_MK20DX256__;_VMDEBUG=1;__MK20DX256__;TEENSYDUINO=127;ARDUINO=10607;F_CPU=96000000;ARDUINO_ARCH_AVR;USB_SERIAL;LAYOUT_US_ENGLISH;__cplusplus=201103L;%(PreprocessorDefinitions) @@ -83,8 +83,12 @@ + + + + VisualMicroDebugger From e65783934f89f4c328feb59da2b8e6aadccbe477 Mon Sep 17 00:00:00 2001 From: Erick Sanchez Date: Sat, 31 Dec 2016 13:01:09 -0800 Subject: [PATCH 2/3] SensorsArray commented values for the Sensor class --- SensorArray.cpp | 18 ++++++++++++++++- SensorArray.h | 45 +++++++++++++++++++++++++++++++++++++++++++ line-follower.vcxproj | 2 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/SensorArray.cpp b/SensorArray.cpp index bfca1e4..a4a2191 100644 --- a/SensorArray.cpp +++ b/SensorArray.cpp @@ -13,19 +13,35 @@ SensorArray::SensorArray() { + sensors = SensorsArray(); } SensorArray::SensorArray(int pins[], int nPins) { + N_SENSORS = nPins; + for (int pin = 0; pin < N_SENSORS; pin++) + { + pinMode(pin, INPUT); + float pos = 2 / N_SENSORS * pin; + sensors.insert(pin, pos); + } } SensorArray::~SensorArray() { + sensors.~SensorsArray(); } double SensorArray::error() { - return 0; + float sum1 = 0, sum2 = 0; + for (int sensor = 0; sensor < N_SENSORS; sensor++) + { + //sum1 += sensors.at(sensor)->position * sensors.at(sensor)->sensor.value(); + //sum2 += sensors.at(sensor)->sensor.value(); + } + + return sum1 / sum2; } diff --git a/SensorArray.h b/SensorArray.h index c914671..1f97a8d 100644 --- a/SensorArray.h +++ b/SensorArray.h @@ -3,8 +3,53 @@ class SensorArray { int N_SENSORS; + struct sensor { + int pin; + int position; + //Sensor *sensor; + sensor *next; + }; + class SensorsArray { + sensor *head, *tail; + public: + SensorsArray() { + head = tail = nullptr; + } + + ~SensorsArray() { + sensor *curr = head; + while (curr != nullptr) { + sensor *destory = curr; + curr = destory->next; + delete destory; + } + } + + //inserts a new node at the tail vs the head + void insert(int pinValue, float posValue) { + sensor *instance = new sensor(); + instance->pin = pinValue; + instance->position = posValue; + tail->next = instance; + + tail = instance; + } + + //starting at 0 as the first node. Iterates starting at the head + sensor* at(int indexValue) { + sensor *node = head; + while (indexValue > 0) { + node = node->next; + indexValue -= 1; + } + + return node; + } + }; + SensorsArray sensors; public: SensorArray(); + //creates sensors and assign positions from -1 to 1, or left to right SensorArray(int pins[], int nPins); ~SensorArray(); double error(); diff --git a/line-follower.vcxproj b/line-follower.vcxproj index 2948fe6..9e56b13 100644 --- a/line-follower.vcxproj +++ b/line-follower.vcxproj @@ -83,10 +83,12 @@ + + From b0e6544326427742f0e934ae28d3df4e84b0c00a Mon Sep 17 00:00:00 2001 From: Erick Sanchez Date: Sat, 31 Dec 2016 13:03:12 -0800 Subject: [PATCH 3/3] rewrote SensorsArray in cpp file --- SensorArray.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ SensorArray.h | 45 ++------------------------------------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/SensorArray.cpp b/SensorArray.cpp index a4a2191..4ea3d45 100644 --- a/SensorArray.cpp +++ b/SensorArray.cpp @@ -10,6 +10,49 @@ #include "WProgram.h" #endif +class SensorsArray { + struct sensor { + int pin; + int position; + //Sensor *sensor; + sensor *next; + }; + sensor *head, *tail; +public: + SensorsArray() { + head = tail = nullptr; + } + + ~SensorsArray() { + sensor *curr = head; + while (curr != nullptr) { + sensor *destory = curr; + curr = destory->next; + delete destory; + } + } + + //inserts a new node at the tail vs the head + void insert(int pinValue, float posValue) { + sensor *instance = new sensor(); + instance->pin = pinValue; + instance->position = posValue; + tail->next = instance; + + tail = instance; + } + + //starting at 0 as the first node. Iterates starting at the head + sensor* at(int indexValue) { + sensor *node = head; + while (indexValue > 0) { + node = node->next; + indexValue -= 1; + } + + return node; + } +}; SensorArray::SensorArray() { diff --git a/SensorArray.h b/SensorArray.h index 1f97a8d..523701d 100644 --- a/SensorArray.h +++ b/SensorArray.h @@ -1,51 +1,10 @@ #pragma once +class SensorsArray; + class SensorArray { int N_SENSORS; - struct sensor { - int pin; - int position; - //Sensor *sensor; - sensor *next; - }; - class SensorsArray { - sensor *head, *tail; - public: - SensorsArray() { - head = tail = nullptr; - } - - ~SensorsArray() { - sensor *curr = head; - while (curr != nullptr) { - sensor *destory = curr; - curr = destory->next; - delete destory; - } - } - - //inserts a new node at the tail vs the head - void insert(int pinValue, float posValue) { - sensor *instance = new sensor(); - instance->pin = pinValue; - instance->position = posValue; - tail->next = instance; - - tail = instance; - } - - //starting at 0 as the first node. Iterates starting at the head - sensor* at(int indexValue) { - sensor *node = head; - while (indexValue > 0) { - node = node->next; - indexValue -= 1; - } - - return node; - } - }; SensorsArray sensors; public: SensorArray();