diff options
Diffstat (limited to 'code/debug/motors/base_drive')
| -rw-r--r-- | code/debug/motors/base_drive/.vscode/extensions.json | 10 | ||||
| -rw-r--r-- | code/debug/motors/base_drive/include/README | 37 | ||||
| -rw-r--r-- | code/debug/motors/base_drive/lib/README | 46 | ||||
| -rw-r--r-- | code/debug/motors/base_drive/platformio.ini | 14 | ||||
| -rw-r--r-- | code/debug/motors/base_drive/src/main.cpp | 233 | ||||
| -rw-r--r-- | code/debug/motors/base_drive/test/README | 11 |
6 files changed, 0 insertions, 351 deletions
diff --git a/code/debug/motors/base_drive/.vscode/extensions.json b/code/debug/motors/base_drive/.vscode/extensions.json deleted file mode 100644 index 080e70d..0000000 --- a/code/debug/motors/base_drive/.vscode/extensions.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] -} diff --git a/code/debug/motors/base_drive/include/README b/code/debug/motors/base_drive/include/README deleted file mode 100644 index 49819c0..0000000 --- a/code/debug/motors/base_drive/include/README +++ /dev/null @@ -1,37 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the convention is to give header files names that end with `.h'. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/code/debug/motors/base_drive/lib/README b/code/debug/motors/base_drive/lib/README deleted file mode 100644 index 9379397..0000000 --- a/code/debug/motors/base_drive/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into the executable file. - -The source code of each library should be placed in a separate directory -("lib/your_library_name/[Code]"). - -For example, see the structure of the following example libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -Example contents of `src/main.c` using Foo and Bar: -``` -#include <Foo.h> -#include <Bar.h> - -int main (void) -{ - ... -} - -``` - -The PlatformIO Library Dependency Finder will find automatically dependent -libraries by scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/code/debug/motors/base_drive/platformio.ini b/code/debug/motors/base_drive/platformio.ini deleted file mode 100644 index a13d034..0000000 --- a/code/debug/motors/base_drive/platformio.ini +++ /dev/null @@ -1,14 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:teensy41] -platform = teensy -board = teensy41 -framework = arduino diff --git a/code/debug/motors/base_drive/src/main.cpp b/code/debug/motors/base_drive/src/main.cpp deleted file mode 100644 index 1130afe..0000000 --- a/code/debug/motors/base_drive/src/main.cpp +++ /dev/null @@ -1,233 +0,0 @@ - -//motor: https://www.pololu.com/product/4861 -//motor driver: https://www.pololu.com/product/2997 - -//Create the timers -IntervalTimer pwm_timer; -IntervalTimer enc_timer; - -//define the pins -//If the motors are spinning incorectly, change pins not the drive function. -int led = 13; - -int m1enA = 6; -int m1enB = 5; -int m1pwm1 = 4; -int m1pwm2 = 3; -int m1encoA = 32; -int m1encoB = 31; - -int m2enA = 12; -int m2enB = 11; -int m2pwm1 = 9; -int m2pwm2 = 10; -int m2encoA = 30; -int m2encoB = 29; - -int m3enA = 27; -int m3enB = 26; -int m3pwm1 = 24; -int m3pwm2 = 25; -int m3encoA = 28; -int m3encoB = 23; - -//PWM variables -int pwmacc = 100; //how accurate the PWM is, means you can enter value from 0 to the value of pwmacc -int PWMval1 = 0; //value of the PWM1, means you can enter value from 0 to the value of pwmacc - -//encoder variables -const int refreshrate = 50; //refresh rate of the encoder -volatile long oneENCcount = 0; //the amount of pulses from motor one encoder - -double ONErpm = 0.00; //the amount of revolutions motor one makes per minute - - - -void setup() { - pinMode(m1enA, OUTPUT); - pinMode(m1enB, OUTPUT); - pinMode(m1pwm1, OUTPUT); - pinMode(m1pwm2, OUTPUT); - - pwm_timer.begin(updatePWM, refreshrate); //speed at wich PWM is updated PWM - enc_timer.begin(enc_refr, 50); //refresh rate of the encoder - - attachInterrupt(digitalPinToInterrupt(m1encoA), AoneIRS, CHANGE); //calls void AoneIRS if there is a change of the stare of m1encoA - attachInterrupt(digitalPinToInterrupt(m1encoB), BoneIRS, CHANGE); //ditto - - Serial.begin(9600); - Serial.print("start"); - SetTunings(1, 1, 1); - -} - -void updatePWM() { - int counter1 = 0; - //PWM one - //if the entered valvue is less the zero set it to zero, because lower that zero is not posible - if (PWMval1 < 0) { - PWMval1 = 0; - } - //if the enterd value is higher than the maximum posible value, set it to max. - if (PWMval1 > pwmacc) { - PWMval1 = pwmacc; - } - //check if the counter has passed the PWM value, and turn of the motor based on that. - if (counter1 < PWMval1) { - digitalWrite(m1enA, HIGH); - } else { - digitalWrite(m1enA, LOW); - } - counter1++; - - if (counter1 >= pwmacc) { - counter1 = 0; - } -} - -void AoneIRS(){ - oneENCcount++; //adds one to the count -} -void BoneIRS(){ - oneENCcount++; //dieselbe -} - -void enc_refr(){ - //calculate RPM. It gets updated 48 times per rotation. - ONErpm = (oneENCcount/48.00) * (60000000.00 / refreshrate); - //reset the counting to zero for next cycle. - oneENCcount = 0; -} -void PID(int speed){ - Serial.println(ONErpm); - PWMval1 = Compute(); //enter output from PID algorith here - digitalWrite(m1enB, LOW); - digitalWrite(m1pwm1, HIGH); - digitalWrite(m1pwm2, LOW); -} - -/*working variables*/ -unsigned long lastTime; -double Input, Output, Setpoint; -double errSum, lastErr; -double kp, ki, kd; -int Compute() -{ - Input = ONErpm; - /*How long since we last calculated*/ - unsigned long now = millis(); - double timeChange = (double)(now - lastTime); - - /*Compute all the working error variables*/ - double error = Setpoint - Input; - errSum += (error * timeChange); - double dErr = (error - lastErr) / timeChange; - -/*Compute PID Output*/ - -/*Remember some variables for next time*/ - lastErr = error; - lastTime = now; - return kp * error + ki * errSum + kd * dErr; -} - -void SetTunings(double Kp, double Ki, double Kd) -{ -kp = Kp; -ki = Ki; -kd = Kd; -} - -//the loop routine runs over and over again forever: -void loop() { - drive(50, 0); //speed value between 0-100 - //Serial.println("Motor one is at: " + ONErpm + " RPM."); - delay(50); -} - -void drive(int speed, int direction){ - // - // Direction............|.Motor 1.|.Motor 2.|.Motor 3. - // 0deg(forward)........|....0....|....-....|....+.... - // 60deg................|....+....|....-....|....0.... - // 120deg...............|....+....|....0....|....-.... - // 180 deg (backward)...|....0....|....+....|....-.... - // 240 deg..............|....-....|....+....|....0.... - // 300 deg..............|....-....|....0....|....+.... - // - - digitalWrite(m1enA, HIGH); - digitalWrite(m2enA, HIGH); - digitalWrite(m3enA, HIGH); - digitalWrite(m1enB, LOW); - digitalWrite(m2enB, LOW); - digitalWrite(m3enB, LOW); - Serial.println("debug2"); - Serial.println(direction); - if(direction>330 || direction<=30){ - //0 deg - digitalWrite(m1pwm1, HIGH); - digitalWrite(m1pwm2, LOW); - - digitalWrite(m2pwm1, LOW); - digitalWrite(m2pwm2, LOW); - - digitalWrite(m3pwm1, HIGH); - digitalWrite(m3pwm2, LOW); - Serial.println("0 deg"); - }else if (direction>30 && direction <= 90){ - //60 deg - Serial.println("60deg"); - digitalWrite(m1pwm1, LOW); - digitalWrite(m1pwm2, LOW); - - digitalWrite(m2pwm1, LOW); - digitalWrite(m2pwm2, HIGH); - - digitalWrite(m3pwm1, LOW); - digitalWrite(m3pwm2, HIGH); - }else if (direction>90 && direction <= 150){ - //120 deg - Serial.println("120 deg"); - digitalWrite(m1pwm1, HIGH); - digitalWrite(m1pwm2, LOW); - digitalWrite(m2pwm1, HIGH); - digitalWrite(m2pwm2, LOW); - digitalWrite(m3pwm1, LOW); - digitalWrite(m3pwm2, LOW); - }else if (direction > 150 && direction <= 210) { - //180 degrees - Serial.println("on 180"); - digitalWrite(m1pwm1, LOW); - digitalWrite(m1pwm2, HIGH); - - digitalWrite(m2pwm1, LOW); - digitalWrite(m2pwm2, LOW); - - digitalWrite(m3pwm1, LOW); - digitalWrite(m3pwm2, HIGH); - }else if (direction > 210 && direction <= 270) { - //240 degrees - digitalWrite(m1pwm1, LOW); - digitalWrite(m1pwm2, LOW); - - digitalWrite(m2pwm1, HIGH); - digitalWrite(m2pwm2, LOW); - - digitalWrite(m3pwm1, LOW); - digitalWrite(m3pwm2, HIGH); - }else if (direction > 270 && direction <= 330) { - //300 degrees - digitalWrite(m1pwm1, HIGH); - digitalWrite(m1pwm2, LOW); - - digitalWrite(m2pwm1, HIGH); - digitalWrite(m2pwm2, LOW); - - Serial.println("300deg"); - digitalWrite(m3pwm1, LOW); - digitalWrite(m3pwm2, LOW); - }else{ - Serial.println("how?"); - } -} diff --git a/code/debug/motors/base_drive/test/README b/code/debug/motors/base_drive/test/README deleted file mode 100644 index 9b1e87b..0000000 --- a/code/debug/motors/base_drive/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PlatformIO Test Runner and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PlatformIO Unit Testing: -- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html |
