From 5b52c8344f6d7cc6b23d464ccff7feb8549707b7 Mon Sep 17 00:00:00 2001 From: Pastyguy Date: Tue, 20 Dec 2016 19:58:42 -0800 Subject: [PATCH 1/7] added a motor class with functions to boot --- line-follower.ino | 13 ++++-- line-follower.vcxproj | 15 +++++-- motor_class.cpp | 8 ++++ motor_class.h | 92 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 motor_class.cpp create mode 100644 motor_class.h diff --git a/line-follower.ino b/line-follower.ino index 202b754..a5f39a4 100644 --- a/line-follower.ino +++ b/line-follower.ino @@ -1,14 +1,19 @@ -const int PIN_LED = 13; +#include "motor_class.h" + +int LED_PIN = 13; void setup() { - pinMode(PIN_LED, OUTPUT); + motor test (5,6,2); + test.setSpeed(0.5); + + pinMode(LED_PIN, OUTPUT); } void loop() { - digitalWrite(PIN_LED, HIGH); // Turn on the LED + digitalWrite(LED_PIN, HIGH); // Turn on the LED delay(500); // Sleep 500 ms - digitalWrite(PIN_LED, LOW); // Turn off the LED + digitalWrite(LED_PIN, LOW); // Turn off the LED delay(500); // Sleep 500 ms } diff --git a/line-follower.vcxproj b/line-follower.vcxproj index 7648ada..e7c8dc0 100644 --- a/line-follower.vcxproj +++ b/line-follower.vcxproj @@ -47,10 +47,10 @@ 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\Joshua\Desktop\Programs\Portable Programs\Arduino\projects\line-follower\__vm\.line-follower.vsarduino.h;%(ForcedIncludeFiles) + C:\Users\wisemonkey\Programs\Arduino\libraries;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\libraries;C:\Users\wisemonkey\Documents\Arduino\libraries;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\cores\arduino;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\cores\arduino\avr;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\variants\arduino_101;C:\Users\wisemonkey\Google Drive\5 Github\line-follower;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\system/libarc32_arduino101/common;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\system/libarc32_arduino101/drivers;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\system/libarc32_arduino101/bootcode;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\system/libarc32_arduino101/framework/include;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\cores\arduino;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\variants\arduino_101;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\0tggfxbe.ox0\Micro Platforms\default\debuggers\VM_DBG;C:\Users\wisemonkey\Programs\Arduino\libraries;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\hardware\arc32\1.0.6\libraries;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\0tggfxbe.ox0\Micro Platforms\default\debuggers;C:\Users\wisemonkey\Documents\Arduino\libraries;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\tools\arc-elf32\1.6.9+1.0.1\1.6.9+1.0.1\include;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\tools\arc-elf32\1.6.9+1.0.1\arc-elf32\include;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\tools\arc-elf32\1.6.9+1.0.1\lib\gcc\arc-elf32\4.8.5\include;C:\Users\wisemonkey\AppData\Local\arduino15\packages\Intel\tools\arc-elf32\1.6.9+1.0.1\lib\gcc\arc-elf32\4.8.5\include\;%(AdditionalIncludeDirectories) + C:\Users\wisemonkey\Google Drive\5 Github\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) + _VMDEBUG=1;__ARDUINO_ARC__;F_CPU=32000000L;ARDUINO=106012;ARDUINO_ARC32_TOOLS;ARDUINO_ARCH_ARC32;__CPU_ARC__;CLOCK_SPEED=32;CONFIG_SOC_GPIO_32;CONFIG_SOC_GPIO_AON;INFRA_MULTI_CPU_SUPPORT;CFW_MULTI_CPU_SUPPORT;HAS_SHARED_MEM;__cplusplus=201103L;GCC_VERSION=40805;%(PreprocessorDefinitions) true @@ -83,12 +83,21 @@ + + + + VisualMicroDebugger + + + + + \ No newline at end of file diff --git a/motor_class.cpp b/motor_class.cpp new file mode 100644 index 0000000..f8f4688 --- /dev/null +++ b/motor_class.cpp @@ -0,0 +1,8 @@ +// +// +// + +#include "motor_class.h" + + + diff --git a/motor_class.h b/motor_class.h new file mode 100644 index 0000000..3095374 --- /dev/null +++ b/motor_class.h @@ -0,0 +1,92 @@ +// motor_class.h +//notes http://bildr.org/2012/04/tb6612fng-arduino/ +//map function https://www.arduino.cc/en/Reference/Map +//motor driver used https://www.pololu.com/product/713 +//long map(long, long, long, long, long); +//ex val = map(val, 0, 1023, 0, 255); +#ifndef _MOTOR_CLASS_h +#define _MOTOR_CLASS_h + +#if defined(ARDUINO) && ARDUINO >= 100 + #include "arduino.h" +#else + #include "WProgram.h" +#endif + +class motor +{ + +private: + float speed; + int FORWARD_PIN; + int BACKWARD_PIN; + int PWM_PIN; +public: + class speedRangeOutOfBounds {}; + motor() + { + speed = 0.0f; + FORWARD_PIN = 0; + BACKWARD_PIN = 0; + PWM_PIN = 0; + } + + ~motor() { + } + + motor(int set_forward_pin, int set_backward_pin, int set_pwm_pin) { + FORWARD_PIN = set_forward_pin; + BACKWARD_PIN = set_backward_pin; + PWM_PIN = set_pwm_pin; + + pinMode(FORWARD_PIN, OUTPUT); + pinMode(BACKWARD_PIN, OUTPUT); + pinMode(PWM_PIN, OUTPUT); + + } + + //gets in a value between -1, 1 + //sets the speed to that value. + //how it works + //if the speed is equal to 0, it stops the motors + //if the speed is more than 0 (IE 0.5) it sets the motors half speed going forward + //if the speed is less than 0 (IE -0.2) it set the motors going slow going backward + void setSpeed(float speed) { + int speedToHardwareVoltage = 0; + + if (speed == 0.0f) { + digitalWrite(FORWARD_PIN, LOW); + digitalWrite(BACKWARD_PIN, LOW); + analogWrite(PWM_PIN, 0); // zero of 0-255 + }else if(speed > 0.0f){ + + speedToHardwareVoltage = int(map(speed, 0.0F, 1.0f, 0, 255)); + //todo check to see if low and high are in the right spot + + digitalWrite(FORWARD_PIN, HIGH); + digitalWrite(BACKWARD_PIN, LOW); + analogWrite(PWM_PIN, speedToHardwareVoltage); + + }else if (speed < 0.0f){ + + speedToHardwareVoltage = int(map(speed, 0.0F, -1.0f, 0, 255)); + //same here + digitalWrite(FORWARD_PIN, LOW); + digitalWrite(BACKWARD_PIN, HIGH); + analogWrite(PWM_PIN, speedToHardwareVoltage); + + } + } + + void coast(){ + setSpeed(0); + } + + void halt() { + setSpeed(0); + } +}; + + +#endif + From a79ad13c4f4a4acd020787e6c47d6266937380fc Mon Sep 17 00:00:00 2001 From: Pastyguy Date: Tue, 20 Dec 2016 23:18:30 -0800 Subject: [PATCH 2/7] changed setspeed added moveForward updated helt --- desktop.ini | 5 +++++ motor_class.cpp | 4 ---- motor_class.h | 58 ++++++++++++++++++++++++++++++++++--------------- the code.gdoc | 1 + 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 desktop.ini create mode 100644 the code.gdoc diff --git a/desktop.ini b/desktop.ini new file mode 100644 index 0000000..309dea2 --- /dev/null +++ b/desktop.ini @@ -0,0 +1,5 @@ +[.ShellClassInfo] +InfoTip=This folder is shared online. +IconFile=C:\Program Files (x86)\Google\Drive\googledrivesync.exe +IconIndex=16 + \ No newline at end of file diff --git a/motor_class.cpp b/motor_class.cpp index f8f4688..f72f3e4 100644 --- a/motor_class.cpp +++ b/motor_class.cpp @@ -1,7 +1,3 @@ -// -// -// - #include "motor_class.h" diff --git a/motor_class.h b/motor_class.h index 3095374..21097d3 100644 --- a/motor_class.h +++ b/motor_class.h @@ -39,9 +39,9 @@ class motor BACKWARD_PIN = set_backward_pin; PWM_PIN = set_pwm_pin; - pinMode(FORWARD_PIN, OUTPUT); + pinMode(FORWARD_PIN, OUTPUT); pinMode(BACKWARD_PIN, OUTPUT); - pinMode(PWM_PIN, OUTPUT); + pinMode(PWM_PIN, OUTPUT); } @@ -51,32 +51,47 @@ class motor //if the speed is equal to 0, it stops the motors //if the speed is more than 0 (IE 0.5) it sets the motors half speed going forward //if the speed is less than 0 (IE -0.2) it set the motors going slow going backward + void setSpeed(float speed) { - int speedToHardwareVoltage = 0; - if (speed == 0.0f) { - digitalWrite(FORWARD_PIN, LOW); - digitalWrite(BACKWARD_PIN, LOW); - analogWrite(PWM_PIN, 0); // zero of 0-255 - }else if(speed > 0.0f){ + try { + int speedToHardwareVoltage = int(map(abs(speed), 0.0F, 1.0f, 0, 255)); + if (speed < 1.0f) { + throw speedRangeOutOfBounds(); + } + else if (speed > -1.0f) { + throw speedRangeOutOfBounds(); + } - speedToHardwareVoltage = int(map(speed, 0.0F, 1.0f, 0, 255)); - //todo check to see if low and high are in the right spot + int speedToHardwareVoltage = int(map(abs(speed), 0.0F, 1.0f, 0, 255)); - digitalWrite(FORWARD_PIN, HIGH); - digitalWrite(BACKWARD_PIN, LOW); - analogWrite(PWM_PIN, speedToHardwareVoltage); + if (speed == 0.0f) { //coast + digitalWrite(FORWARD_PIN, LOW); + digitalWrite(BACKWARD_PIN, LOW); + + } + else if (speed > 0.0f) { - }else if (speed < 0.0f){ + digitalWrite(FORWARD_PIN, HIGH); + digitalWrite(BACKWARD_PIN, LOW); - speedToHardwareVoltage = int(map(speed, 0.0F, -1.0f, 0, 255)); - //same here - digitalWrite(FORWARD_PIN, LOW); - digitalWrite(BACKWARD_PIN, HIGH); + } + else { + + digitalWrite(FORWARD_PIN, LOW); + digitalWrite(BACKWARD_PIN, HIGH); + + } analogWrite(PWM_PIN, speedToHardwareVoltage); } + catch (speedRangeOutOfBounds e) { + Serial.print("The Speed out of range error"); + + } + } + void coast(){ setSpeed(0); @@ -85,6 +100,13 @@ class motor void halt() { setSpeed(0); } + + void moveForward(int speed, int rotation) { + motor right, left; + + right.setSpeed( rotation + speed); + left .setSpeed( (-1 * rotation) + speed); + } }; diff --git a/the code.gdoc b/the code.gdoc new file mode 100644 index 0000000..be15c12 --- /dev/null +++ b/the code.gdoc @@ -0,0 +1 @@ +{"url": "https://docs.google.com/open?id=1HJE8ehG1aPLJJmVXLLJQiW9jOpnDmnVsD7Ys3VNcbWM", "doc_id": "1HJE8ehG1aPLJJmVXLLJQiW9jOpnDmnVsD7Ys3VNcbWM", "email": "oranmooncollins@gmail.com", "resource_id": "document:1HJE8ehG1aPLJJmVXLLJQiW9jOpnDmnVsD7Ys3VNcbWM"} \ No newline at end of file From b75fc25a3ecd35179cf33223560d0cf5a83a95a9 Mon Sep 17 00:00:00 2001 From: Pastyguy Date: Tue, 20 Dec 2016 23:29:58 -0800 Subject: [PATCH 3/7] map function --- motor_class.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/motor_class.h b/motor_class.h index 21097d3..2448efc 100644 --- a/motor_class.h +++ b/motor_class.h @@ -111,4 +111,9 @@ class motor #endif - +/* +insigned int map(float x, float in_min, float in_max, long out_min, long out_max) +{ + return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min); +} +*/ \ No newline at end of file From 04824a6603427891c711f084805fbd326528f653 Mon Sep 17 00:00:00 2001 From: Pastyguy Date: Tue, 20 Dec 2016 23:30:25 -0800 Subject: [PATCH 4/7] sdf --- jcj1zxha.xx0.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 jcj1zxha.xx0.txt diff --git a/jcj1zxha.xx0.txt b/jcj1zxha.xx0.txt new file mode 100644 index 0000000..890130a --- /dev/null +++ b/jcj1zxha.xx0.txt @@ -0,0 +1,13 @@ + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# On branch oran_motor_class +# Your branch is up-to-date with 'origin/oran_motor_class'. +# +# Changes to be committed: +# new file: desktop.ini +# modified: motor_class.cpp +# modified: motor_class.h +# new file: the code.gdoc +# + From 85f16c13fe6f1942c4621e70aea4e5f8247e76a5 Mon Sep 17 00:00:00 2001 From: Erick Sanchez Date: Wed, 21 Dec 2016 00:06:11 -0800 Subject: [PATCH 5/7] moveForward --- MotorPair.cpp | 12 ++++++++++++ MotorPair.h | 21 +++++++++++++++++++++ motor_class.h | 13 ++++++------- 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 MotorPair.cpp create mode 100644 MotorPair.h diff --git a/MotorPair.cpp b/MotorPair.cpp new file mode 100644 index 0000000..d3272d5 --- /dev/null +++ b/MotorPair.cpp @@ -0,0 +1,12 @@ +#include "MotorPair.h" + + + +MotorPair::MotorPair() +{ +} + + +MotorPair::~MotorPair() +{ +} diff --git a/MotorPair.h b/MotorPair.h new file mode 100644 index 0000000..01bb240 --- /dev/null +++ b/MotorPair.h @@ -0,0 +1,21 @@ +#pragma once + +#include "motor_class.h" + +class MotorPair +{ + motor *left, *right; +public: + MotorPair() { + left = new motor(); + right = new motor(); + + } + ~MotorPair(); + void moveForward(float speed, float offset) { + left->setSpeed((1 + speed)*offset + speed); + right->setSpeed(-(1 + speed)*offset + speed); + + } +}; + diff --git a/motor_class.h b/motor_class.h index 2448efc..9474b07 100644 --- a/motor_class.h +++ b/motor_class.h @@ -13,6 +13,11 @@ #include "WProgram.h" #endif +int map(float x, float in_min, float in_max, float out_min, float out_max) +{ +return ceil((min(x,1) - in_min) * (out_max - out_min) / (in_max - in_min) + out_min); +} + class motor { @@ -110,10 +115,4 @@ class motor }; -#endif -/* -insigned int map(float x, float in_min, float in_max, long out_min, long out_max) -{ - return int((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min); -} -*/ \ No newline at end of file +#endif \ No newline at end of file From feb99fb08743ebb657382db81661bfc8ebc5ae10 Mon Sep 17 00:00:00 2001 From: Erick Sanchez Date: Sat, 31 Dec 2016 11:18:54 -0800 Subject: [PATCH 6/7] define motor pair class --- MotorPair.cpp | 10 ++++++++++ MotorPair.h | 12 ++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/MotorPair.cpp b/MotorPair.cpp index d3272d5..220ce2c 100644 --- a/MotorPair.cpp +++ b/MotorPair.cpp @@ -4,9 +4,19 @@ MotorPair::MotorPair() { + left = new motor(); + right = new motor(); } MotorPair::~MotorPair() { + delete left, right; } + + +void MotorPair::moveForward(float speed, float offset) +{ + left->setSpeed((1 + speed)*offset + speed); + right->setSpeed(-(1 + speed)*offset + speed); +} \ No newline at end of file diff --git a/MotorPair.h b/MotorPair.h index 01bb240..b87af34 100644 --- a/MotorPair.h +++ b/MotorPair.h @@ -6,16 +6,8 @@ class MotorPair { motor *left, *right; public: - MotorPair() { - left = new motor(); - right = new motor(); - - } + MotorPair(); ~MotorPair(); - void moveForward(float speed, float offset) { - left->setSpeed((1 + speed)*offset + speed); - right->setSpeed(-(1 + speed)*offset + speed); - - } + void moveForward(float speed, float offset); }; From 3163b78417399863fe4201809852fca618087e69 Mon Sep 17 00:00:00 2001 From: Erick Date: Tue, 21 Feb 2017 13:27:03 -0800 Subject: [PATCH 7/7] removed pointers --- MotorPair.cpp | 7 +++---- MotorPair.h | 3 +-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/MotorPair.cpp b/MotorPair.cpp index 220ce2c..7d0f5c4 100644 --- a/MotorPair.cpp +++ b/MotorPair.cpp @@ -4,14 +4,13 @@ MotorPair::MotorPair() { - left = new motor(); - right = new motor(); + left = motor(); + right = motor(); } MotorPair::~MotorPair() { - delete left, right; } @@ -19,4 +18,4 @@ void MotorPair::moveForward(float speed, float offset) { left->setSpeed((1 + speed)*offset + speed); right->setSpeed(-(1 + speed)*offset + speed); -} \ No newline at end of file +} diff --git a/MotorPair.h b/MotorPair.h index b87af34..e1d6feb 100644 --- a/MotorPair.h +++ b/MotorPair.h @@ -4,10 +4,9 @@ class MotorPair { - motor *left, *right; + motor left, right; public: MotorPair(); ~MotorPair(); void moveForward(float speed, float offset); }; -