Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions SensorArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#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

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()
{
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()
{
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;
}
16 changes: 16 additions & 0 deletions SensorArray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

class SensorsArray;

class SensorArray
{
int N_SENSORS;
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();
};

8 changes: 7 additions & 1 deletion line-follower.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>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)</AdditionalIncludeDirectories>
<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)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>C:\Users\Joshua\Desktop\Programs\Portable Programs\Arduino\projects\line-follower\__vm\.line-follower.vsarduino.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<PreprocessorDefinitions>__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)</PreprocessorDefinitions>
Expand Down Expand Up @@ -83,8 +83,14 @@
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SenorArray.h" />
<ClInclude Include="SensorArray.h" />
<ClInclude Include="__vm\.line-follower.vsarduino.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="SenorArray.cpp" />
<ClCompile Include="SensorArray.cpp" />
</ItemGroup>
<PropertyGroup>
<DebuggerFlavor>VisualMicroDebugger</DebuggerFlavor>
</PropertyGroup>
Expand Down