summaryrefslogtreecommitdiff
path: root/OLD_CODE_REMOVE_LATER/debug/driving
diff options
context:
space:
mode:
Diffstat (limited to 'OLD_CODE_REMOVE_LATER/debug/driving')
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/driving/3mtest/3mtest.ino92
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/driving/base_drive/base_drive.ino140
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/driving/base_drive_with_speed_control/base_drive_with_speed_control.ino214
-rw-r--r--OLD_CODE_REMOVE_LATER/debug/driving/onemotor_softPWM/onemotor_softPWM.ino126
4 files changed, 0 insertions, 572 deletions
diff --git a/OLD_CODE_REMOVE_LATER/debug/driving/3mtest/3mtest.ino b/OLD_CODE_REMOVE_LATER/debug/driving/3mtest/3mtest.ino
deleted file mode 100644
index da87ab5..0000000
--- a/OLD_CODE_REMOVE_LATER/debug/driving/3mtest/3mtest.ino
+++ /dev/null
@@ -1,92 +0,0 @@
-//a test to test all motors, no PWM
-
-
-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;
-
-
-void setup() {
- pinMode(m1enA, OUTPUT);
- pinMode(m1enB, OUTPUT);
- pinMode(m1pwm1, OUTPUT);
- pinMode(m1pwm2, OUTPUT);
-
- pinMode(m2enA, OUTPUT);
- pinMode(m2enB, OUTPUT);
- pinMode(m2pwm1, OUTPUT);
- pinMode(m2pwm2, OUTPUT);
-
- pinMode(m3enA, OUTPUT);
- pinMode(m3enB, OUTPUT);
- pinMode(m3pwm1, OUTPUT);
- pinMode(m3pwm2, OUTPUT);
- Serial.begin(9600);
- Serial.print("debug 001");
-
-}
-
-// the loop routine runs over and over again forever:
-void loop() {
- digitalWrite(led, HIGH);
-
- digitalWrite(m1enA, HIGH);
- digitalWrite(m1enB, LOW);
- digitalWrite(m1pwm1, HIGH);
- digitalWrite(m1pwm2, LOW);
-
-
- digitalWrite(m2enA, HIGH);
- digitalWrite(m2enB, LOW);
- digitalWrite(m2pwm1, HIGH);
- digitalWrite(m2pwm2, LOW);
-
- digitalWrite(m3enA, HIGH);
- digitalWrite(m3enB, LOW);
- digitalWrite(m3pwm1, HIGH);
- digitalWrite(m3pwm2, LOW);
-
- delay(5000);
-
-
- digitalWrite(led, LOW);
-
- digitalWrite(m1enA, HIGH);
- digitalWrite(m1enB, LOW);
- digitalWrite(m1pwm1, LOW);
- digitalWrite(m1pwm2, LOW);
-
- digitalWrite(m2enA, HIGH);
- digitalWrite(m2enB, LOW);
- digitalWrite(m2pwm1, LOW);
- digitalWrite(m2pwm2, LOW);
-
- digitalWrite(m3enA, HIGH);
- digitalWrite(m3enB, LOW);
- digitalWrite(m3pwm1, LOW);
- digitalWrite(m3pwm2, LOW);
-
-
- delay(5000);
-
-
-}
diff --git a/OLD_CODE_REMOVE_LATER/debug/driving/base_drive/base_drive.ino b/OLD_CODE_REMOVE_LATER/debug/driving/base_drive/base_drive.ino
deleted file mode 100644
index 0e82170..0000000
--- a/OLD_CODE_REMOVE_LATER/debug/driving/base_drive/base_drive.ino
+++ /dev/null
@@ -1,140 +0,0 @@
-//base code for six direction driving
-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;
-
-void setup() {
- pinMode(m1enA, OUTPUT);
- pinMode(m1enB, OUTPUT);
- pinMode(m1pwm1, OUTPUT);
- pinMode(m1pwm2, OUTPUT);
-
- pinMode(m2enA, OUTPUT);
- pinMode(m2enB, OUTPUT);
- pinMode(m2pwm1, OUTPUT);
- pinMode(m2pwm2, OUTPUT);
-
- pinMode(m3enA, OUTPUT);
- pinMode(m3enB, OUTPUT);
- pinMode(m3pwm1, OUTPUT);
- pinMode(m3pwm2, OUTPUT);
- Serial.begin(9600);
- Serial.print("start");
-
-}
-
-
-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, LOW);
- digitalWrite(m1pwm2, HIGH);
-
- digitalWrite(m2pwm1, LOW);
- digitalWrite(m2pwm2, LOW);
-
- digitalWrite(m3pwm1, LOW);
- digitalWrite(m3pwm2, HIGH);
- Serial.println("0 deg");
- }else if (direction>30 && direction <= 90){
- //60 deg
- Serial.println("60deg");
- digitalWrite(m1pwm1, LOW);
- digitalWrite(m1pwm2, LOW);
-
- digitalWrite(m2pwm1, HIGH);
- digitalWrite(m2pwm2, LOW);
-
- 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, HIGH);
- digitalWrite(m1pwm2, LOW);
-
- digitalWrite(m2pwm1, LOW);
- digitalWrite(m2pwm2, LOW);
-
- digitalWrite(m3pwm1, HIGH);
- digitalWrite(m3pwm2, LOW);
- }else if (direction > 210 && direction <= 270) {
- //240 degrees
- digitalWrite(m1pwm1, LOW);
- digitalWrite(m1pwm2, LOW);
-
- digitalWrite(m2pwm1, LOW);
- digitalWrite(m2pwm2, HIGH);
-
- digitalWrite(m3pwm1, HIGH);
- digitalWrite(m3pwm2, LOW);
- }else if (direction > 270 && direction <= 330) {
- //300 degrees
- digitalWrite(m1pwm1, LOW);
- digitalWrite(m1pwm2, HIGH);
- digitalWrite(m2pwm1, LOW);
- digitalWrite(m2pwm2, HIGH);
- Serial.println("300deg");
- digitalWrite(m3pwm1, LOW);
- digitalWrite(m3pwm2, LOW);
- }else{
- Serial.println("how?");
- }
-}
-
-// the loop routine runs over and over again forever:
-void loop() {
- drive(255, 0);
- Serial.println("ffor");
- delay(1500);
- drive(255, 180);
- Serial.println("back");
- delay(1500);
-
-}
diff --git a/OLD_CODE_REMOVE_LATER/debug/driving/base_drive_with_speed_control/base_drive_with_speed_control.ino b/OLD_CODE_REMOVE_LATER/debug/driving/base_drive_with_speed_control/base_drive_with_speed_control.ino
deleted file mode 100644
index e5a783e..0000000
--- a/OLD_CODE_REMOVE_LATER/debug/driving/base_drive_with_speed_control/base_drive_with_speed_control.ino
+++ /dev/null
@@ -1,214 +0,0 @@
-#include <TimerThree.h>
-
-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;
-
-int speed = 1000; // speed 0-1
-
-double sp1 = 0.00;
-double sp2 = 0.00;
-double sp3 = 0.00;
-
-volatile int PWMval1 = 0; // PWM value 0-100
-volatile int PWMval2 = 0; // PWM value 0-100
-volatile int PWMval3 = 0; // PWM value 0-100
-
-
-void setup() {
- pinMode(m1enA, OUTPUT);
- pinMode(m1enB, OUTPUT);
- pinMode(m1pwm1, OUTPUT);
- pinMode(m1pwm2, OUTPUT);
-
- pinMode(m2enA, OUTPUT);
- pinMode(m2enB, OUTPUT);
- pinMode(m2pwm1, OUTPUT);
- pinMode(m2pwm2, OUTPUT);
-
- pinMode(m3enA, OUTPUT);
- pinMode(m3enB, OUTPUT);
- pinMode(m3pwm1, OUTPUT);
- pinMode(m3pwm2, OUTPUT);
-
- Timer3.initialize(800); // 800 microseconds or 1.25kHz
- Timer3.attachInterrupt(updatePWM);
-
- Serial.begin(9600);
-}
-
-void updatePWM() {
- static int counter = 0;
-
- if (counter < PWMval1) {
- digitalWrite(m1enA, HIGH);
- } else {
- digitalWrite(m1enA, LOW);
- }
-
- if (counter < PWMval2) {
- digitalWrite(m2enA, HIGH);
- } else {
- digitalWrite(m2enA, LOW);
- }
-
- if (counter < PWMval3) {
- digitalWrite(m3enA, HIGH);
- } else {
- digitalWrite(m3enA, LOW);
- }
-
- counter++;
- if (counter >= 100) {
- counter = 0;
- }
-}
-
-void mcpsoftpwm1(int value1) {
- if (value1 < 0) value1 = 0;
- if (value1 > 100) value1 = 100;
-
- Serial.print("softPWM pin: enA, value: ");
- Serial.println(value1);
- PWMval1 = value1;
-}
-void mcpsoftpwm2(int value2) {
- if (value2 < 0) value2 = 0;
- if (value2 > 100) value2 = 100;
-
- Serial.print("softPWM pin: enA, value: ");
- Serial.println(value2);
- PWMval2 = value2;
-}void mcpsoftpwm3(int value3) {
- if (value3 < 0) value3 = 0;
- if (value3 > 100) value3 = 100;
-
- Serial.print("softPWM pin: enA, value: ");
- Serial.println(value3);
- PWMval3 = value3;
-}
-
-void move1(int sped1) {
- sp1 = abs(sped1)*0.1;
- mcpsoftpwm1(sp1);
- digitalWrite(m1enB, LOW);
- if (sped1 < 0) {
- Serial.print("back ");
- digitalWrite(m1pwm1, LOW);
- digitalWrite(m1pwm2, HIGH);
- } else {
- Serial.print("forward ");
- digitalWrite(m1pwm1, HIGH);
- digitalWrite(m1pwm2, LOW);
- }
- Serial.println(sp1);
-}
-
-void move2(int sped2) {
- sp2 = abs(sped2)*0.1;
- mcpsoftpwm2(sp2);
- digitalWrite(m2enB, LOW);
- if (sped2 < 0) {
- Serial.print("back ");
- digitalWrite(m2pwm1, LOW);
- digitalWrite(m2pwm2, HIGH);
- } else {
- Serial.print("forward ");
- digitalWrite(m2pwm1, HIGH);
- digitalWrite(m2pwm2, LOW);
- }
- Serial.println(sp2);
-}
-
-void move3(int sped3) {
- sp3 = abs(sped3)*0.1;
- mcpsoftpwm3(sp3);
- digitalWrite(m3enB, LOW);
- if (sped3 < 0) {
- Serial.print("back ");
- digitalWrite(m3pwm1, LOW);
- digitalWrite(m3pwm2, HIGH);
- } else {
- Serial.print("forward ");
- digitalWrite(m3pwm1, HIGH);
- digitalWrite(m3pwm2, LOW);
- }
- Serial.println(sp3);
-}
-
-void drive(int speeeed, 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....|....+....
- //
- if(direction>330 || direction<=30){
- //0 deg
- //Serial.println("drive 0 deg");
- move1(0);
- move2(-speeeed);
- move3(speeeed);
- }else if (direction>30 && direction <= 90){
- //60 deg
- //Serial.println("drive 60deg");
- move1(speeeed);
- move2(-speeeed);
- move3(0);
- }else if (direction>90 && direction <= 150){
- //120 deg
- //Serial.println("drive 120 deg");
- move1(speeeed);
- move2(0);
- move3(-speeeed);
- }else if (direction > 150 && direction <= 210) {
- //180 degrees
- //Serial.println("drive 180 deg");
- move1(0);
- move2(speeeed);
- move3(-speeeed);
- }else if (direction > 210 && direction <= 270) {
- //240 degrees
- //Serial.println("drive 240 deg");
- move1(-speeeed);
- move2(speeeed);
- move3(0);
- }else if (direction > 270 && direction <= 330) {
- //300 degrees
- //Serial.println("drive 300 deg");
- move1(-speeeed);
- move2(0);
- move3(speeeed);
- }else{
- Serial.println("how?");
- }
-}
-
-void loop() {
- drive(1000, 0);
- Serial.println("ffor");
- delay(1500);
- drive(500, 180);
- Serial.println("back");
- delay(3000);
-}
diff --git a/OLD_CODE_REMOVE_LATER/debug/driving/onemotor_softPWM/onemotor_softPWM.ino b/OLD_CODE_REMOVE_LATER/debug/driving/onemotor_softPWM/onemotor_softPWM.ino
deleted file mode 100644
index 68d95dd..0000000
--- a/OLD_CODE_REMOVE_LATER/debug/driving/onemotor_softPWM/onemotor_softPWM.ino
+++ /dev/null
@@ -1,126 +0,0 @@
-#include <TimerThree.h>
-
-int enA = 6; //PWM pin
-int enB = 5; //GND
-int pwm1 = 4; //
-int pwm2 = 3;
-int encoA = 32;
-int encoB = 31;
-
-int speed = 1000; // speed 0-1
-
-double sp = 0.00;
-double rpm = 0.00;
-volatile long encount = 0;
-unsigned long Ltime = 0;
-unsigned long Ctime = 0;
-unsigned long Ptime = 0;
-
-volatile int PWMval = 0; // PWM value 0-100
-
-
-void setup() {
- pinMode(enA, OUTPUT);
- pinMode(enB, OUTPUT);
- pinMode(pwm1, OUTPUT);
- pinMode(pwm2, OUTPUT);
-
- pinMode(encoA, INPUT_PULLUP);
- pinMode(encoB, INPUT_PULLUP);
-
- attachInterrupt(digitalPinToInterrupt(encoA), encoderISR, CHANGE);
- attachInterrupt(digitalPinToInterrupt(encoB), encoderISR, CHANGE);
-
- Timer3.initialize(800); // 800 microseconds or 1.25kHz
- Timer3.attachInterrupt(updatePWM);
-
- Serial.begin(9600);
-}
-
-void updatePWM() {
- static int counter = 0;
-
- if (counter < PWMval) {
- digitalWrite(enA, HIGH);
- } else {
- digitalWrite(enA, LOW);
- }
-
- counter++;
- if (counter >= 100) {
- counter = 0;
- }
-}
-void mcpsoftpwm(int value) {
- if (value < 0) value = 0;
- if (value > 100) value = 100;
-
- Serial.print("softPWM pin: enA, value: ");
- Serial.println(value);
- PWMval = value;
-}
-
-void encoderISR() {
- encount++;
-}
-
-void readenc() {
- Ctime = micros();
- Ptime = Ctime - Ltime;
- Ltime = Ctime;
- rpm = (encount / 211.2) * (60000000.0 / Ptime);
- Serial.print("RPM: ");
- Serial.print(rpm);
- Serial.print(" Sample period:");
- Serial.print(Ptime);
- Serial.print("ms, encoder count:");
- Serial.println(encount);
-
- encount = 0;
-}
-void resetenc(){
- Ctime = micros();
- Ltime = Ctime;
- encount = 0;
-}
-
-void move(int sped) {
- sp = abs(sped)*0.1;
- mcpsoftpwm(sp);
- digitalWrite(enB, LOW);
- if (sped < 0) {
- Serial.print("back ");
- digitalWrite(pwm1, LOW);
- digitalWrite(pwm2, HIGH);
- } else {
- Serial.print("forward ");
- digitalWrite(pwm1, HIGH);
- digitalWrite(pwm2, LOW);
- }
- Serial.println(sp);
-}
-
-void loop() {
- move(speed);
- delay(1000);
- readenc();
- delay(1000);
-
- Serial.println();
-
- move(0);
- delay(1000);
- resetenc();
- delay(1000);
- readenc();
- delay(1000);
-
- Serial.println();
-
- move(500);
- delay(1000);
- readenc();
- delay(1000);
-
- Serial.println();
-}