diff --git a/Hello b/Hello old mode 100644 new mode 100755 diff --git a/Modification_du_corps/README b/Modification_du_corps/README old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example.pde b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example.pde old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/AutoTune_Example.pde b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/AutoTune_Example.pde old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_AutoTune_v0.cpp b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_AutoTune_v0.cpp old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_AutoTune_v0.h b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_AutoTune_v0.h old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_v1.cpp b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_v1.cpp old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_v1.h b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/AutoTune_Example/PID_v1.h old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/Examples/AutoTune_Example/AutoTune_Example.pde b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/Examples/AutoTune_Example/AutoTune_Example.pde old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/PID_AutoTune_v0.cpp b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/PID_AutoTune_v0.cpp old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/PID_AutoTune_v0.h b/Moteur DC/Arduino-PID-AutoTune-Library/PID_AutoTune_v0/PID_AutoTune_v0.h old mode 100644 new mode 100755 diff --git a/Moteur DC/Arduino-PID-AutoTune-Library/README.txt b/Moteur DC/Arduino-PID-AutoTune-Library/README.txt old mode 100644 new mode 100755 diff --git a/Moteur DC/DC_servo/DC_1servo.7z b/Moteur DC/DC_servo/DC_1servo.7z old mode 100644 new mode 100755 diff --git a/Moteur DC/DC_servo/DC_1servo/DC_1servo.ino b/Moteur DC/DC_servo/DC_1servo/DC_1servo.ino old mode 100644 new mode 100755 diff --git a/Moteur DC/DC_servo/DC_1servo/PID_v1.cpp b/Moteur DC/DC_servo/DC_1servo/PID_v1.cpp old mode 100644 new mode 100755 diff --git a/Moteur DC/DC_servo/DC_1servo/PID_v1.h b/Moteur DC/DC_servo/DC_1servo/PID_v1.h old mode 100644 new mode 100755 diff --git a/Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.0.pde b/Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.0.pde old mode 100644 new mode 100755 diff --git a/Moteur DC/ServoStrap/LICENSE b/Moteur DC/ServoStrap/LICENSE old mode 100644 new mode 100755 diff --git a/Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation.pde b/Moteur DC/ServoStrap/OLD/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation.pde old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation.pde rename to Moteur DC/ServoStrap/OLD/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation.pde diff --git a/Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/STM32_olimexino_stepper_motor_emulator b/Moteur DC/ServoStrap/OLD/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/STM32_olimexino_stepper_motor_emulator old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/STM32_olimexino_stepper_motor_emulator rename to Moteur DC/ServoStrap/OLD/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/STM32_olimexino_stepper_motor_emulator diff --git a/Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/keywords.txt b/Moteur DC/ServoStrap/OLD/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/keywords.txt old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/keywords.txt rename to Moteur DC/ServoStrap/OLD/Arduino_stepper_motor_emulator_v1.0.1_direct_port_manipulation/keywords.txt diff --git a/Moteur DC/ServoStrap/Driver_printer/Driver_printer.ino b/Moteur DC/ServoStrap/OLD/Driver_printer/Driver_printer.ino old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/Driver_printer/Driver_printer.ino rename to Moteur DC/ServoStrap/OLD/Driver_printer/Driver_printer.ino diff --git a/Moteur DC/ServoStrap/Driver_printer/libraries/digitalWriteFast.h b/Moteur DC/ServoStrap/OLD/Driver_printer/libraries/digitalWriteFast.h old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/Driver_printer/libraries/digitalWriteFast.h rename to Moteur DC/ServoStrap/OLD/Driver_printer/libraries/digitalWriteFast.h diff --git a/Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.0.pde b/Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.0.pde old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.0.pde rename to Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.0.pde diff --git a/Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1AVEC_ENA.ino b/Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1AVEC_ENA.ino old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1AVEC_ENA.ino rename to Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1AVEC_ENA.ino diff --git a/Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA.ino b/Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA.ino old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA.ino rename to Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA.ino diff --git a/Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2.ino b/Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2.ino old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2.ino rename to Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2/ServoStrap_Port_manipulation_LD293D-1.1SS_ENA2.ino diff --git a/Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D_1_0_pde.ino b/Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D_1_0_pde.ino old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D_1_0_pde.ino rename to Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/ServoStrap_Port_manipulation_LD293D_1_0_pde.ino diff --git a/Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/digitalWriteFast.h b/Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/digitalWriteFast.h old mode 100644 new mode 100755 similarity index 100% rename from Moteur DC/ServoStrap/ServoStrap_Port_manipulation_LD293D/digitalWriteFast.h rename to Moteur DC/ServoStrap/OLD/ServoStrap_Port_manipulation_LD293D/digitalWriteFast.h diff --git a/Moteur DC/ServoStrap/README.md b/Moteur DC/ServoStrap/README.md old mode 100644 new mode 100755 diff --git a/Moteur DC/ServoStrap/STM32_olimexino_stepper_motor_emulator b/Moteur DC/ServoStrap/STM32_olimexino_stepper_motor_emulator old mode 100644 new mode 100755 diff --git a/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_0/ServoStrapPortManipulationLD293D_1_0.ino b/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_0/ServoStrapPortManipulationLD293D_1_0.ino old mode 100644 new mode 100755 diff --git a/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_1/ServoStrapPortManipulationLD293D_1_1.ino b/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_1/ServoStrapPortManipulationLD293D_1_1.ino new file mode 100755 index 0000000..7fd71a5 --- /dev/null +++ b/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_1/ServoStrapPortManipulationLD293D_1_1.ino @@ -0,0 +1,229 @@ +#include +//this is to use DWF library, it will increase the speed of digitalRead/Write command +//used in the interrupt function doEncoderMotor0, but may be used everywhere. +/* +https://github.com/danithebest91/ServoStrap + i have made this code for the LMD18245 motor controller, + i have merged the pid code of Josh Kopel + whith the code of makerbot servo-controller board, + you can use this code on the some board changing some values. + Daniele Poddighe + external ardware require a quadrature encoder, timing slit strip and a dc motor, + all you can find inside an old printer, i have took it from canon and hp printers(psc1510) + + for motor controll you can choose different type of H-bridge, i have used LMD18245, + you can order 3 of it on ti.com sample request, the hardware needed is explained on the datasheet but i'm drowing + the schematic and PCB layout on eagle. + + + read a rotary encoder with interrupts + Encoder hooked up with common to GROUND, + encoder0PinA to pin 2, encoder0PinB to pin 4 (or pin 3 see below) + it doesn't matter which encoder pin you use for A or B + + is possible to change PID costants by sending on serial interfaces the values separated by ',' in this order: KP,KD,KI + example: 5.2,3.1,0 so we have KP=5.2 KD=3.1 KI=0 is only for testing purposes, but i will leave this function with eeprom storage + + This code use Port manipulation : + Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Arduino board. The chips used on the Arduino board + (the ATmega8 and ATmega168) have three ports: + B (digital pin 8 to 13) + C (analog input pins) + D (digital pins 0 to 7) + https://www.arduino.cc/en/Reference/PortManipulation + + https://www.arduino.cc/en/Hacking/PinMapping + https://www.arduino.cc/en/Hacking/PinMapping168 +*/ + +#define encoder0PinA 2 // PD2 (INT0) You can't modify port mapping here because this code use Port manipulation (I2) +#define encoder0PinB 8 // PB0; (I8) + +#define MotorIN1 5 //(I5) IN1 +#define MotorIN2 6 //(I6) IN2 + +//from ramps 1.4 stepper driver +#define STEP_PIN 3 //PD3 (INT1) (I3) +#define DIR_PIN 14 //PC0; (A0) +#define X_MIN 4 //(4) + +volatile long encoder0Pos = 0; + +long target = 0; +long target1 = 0; +int StartRoutine=0; +//correction = Kp * error + Kd * (error - prevError) + kI * (sum of errors) +//PID controller constants +float KP = 2.25 ; //position multiplier (gain) 2.25 +float KI = 0.25; // Intergral multiplier (gain) .25 +float KD = 1.0; // derivative multiplier (gain) 1.0 + +int lastError = 0; +int sumError = 0; + +//Integral term min/max (random value and not yet tested/verified) +int iMax = 100; +int iMin = 0; + +long previousTarget = 0; +long previousMillis = 0; // will store last time LED was updated +long interval = 5; // interval at which to blink (milliseconds) + +//for motor control ramps 1.4 +bool newStep = false; +bool oldStep = false; +bool dir = false; + +void setup() { + pinModeFast(2, INPUT); + pinModeFast(encoder0PinA, INPUT); + pinModeFast(encoder0PinB, INPUT); + pinModeFast(X_MIN, INPUT); + + + pinModeFast(MotorIN1, OUTPUT); + pinModeFast(MotorIN2, OUTPUT); + + //ramps 1.4 motor control + pinModeFast(STEP_PIN, INPUT); + pinModeFast(DIR_PIN, INPUT); + + attachInterrupt(0, doEncoderMotor0, CHANGE); // encoder pin on interrupt 0 - pin 2 + attachInterrupt(1, countStep, RISING); //on pin 3 + + Serial.begin (115200); + Serial.println("start"); // a personal quirk + +} + +void loop(){ + + while (Serial.available() > 0) { + KP = Serial.parseFloat(); + KD = Serial.parseFloat(); + KI = Serial.parseFloat(); + + + Serial.println(KP); + Serial.println(KD); + Serial.println(KI); +} + Fstart(); + if(millis() - previousTarget > 1000){ //enable this code only for test purposes because it loss a lot of time + + if (X_MIN == LOW) Serial.print("LOW"); + else Serial.print("HIGH"); + Serial.print(','); + Serial.print(encoder0Pos); + Serial.print(','); + Serial.println(target1); + previousTarget=millis(); + } + + target = target1; + docalc(); +} + +void Fstart(){ + + if (StartRoutine == 0) + { + digitalWrite ( MotorIN1 , LOW ); + analogWrite ( MotorIN2, 200 ); + delay(2000); + digitalWrite ( MotorIN2 , LOW ); + analogWrite ( MotorIN1, 255 ); + delay(200); + digitalWrite ( MotorIN1, LOW ); + analogWrite ( MotorIN2, 255 ); + delay(180); + digitalWrite ( MotorIN2, LOW ); + analogWrite ( MotorIN1, 255 ); + delay(100); + digitalWrite ( MotorIN1, LOW ); + analogWrite ( MotorIN2, 255 ); + delay(90); + digitalWrite ( MotorIN2, LOW ); + analogWrite ( MotorIN1, 255 ); + delay(100); + digitalWrite ( MotorIN1, LOW ); + analogWrite ( MotorIN2, 200 ); + delay(2000); + + + StartRoutine = 1; + encoder0Pos=0; + } + +} + +void docalc() { + + if (millis() - previousMillis > interval) + { + previousMillis = millis(); + long error = encoder0Pos - target ; // find the error term of current position - target + + //generalized PID formula + //correction = Kp * error + Kd * (error - prevError) + kI * (sum of errors) + long motorspeed = KP * error + KD * (error - lastError) +KI * (sumError); + + lastError = error; + sumError += error; + + //scale the sum for the integral term + if(sumError > iMax) { + sumError = iMax; + } else if(sumError < iMin){ + sumError = iMin; + } + + if(motorspeed > 0){ + if( motorspeed >= 255) motorspeed=255; + digitalWrite ( MotorIN1 , LOW ); + analogWrite ( MotorIN2, motorspeed ); + } + if(motorspeed < 0){ + motorspeed = -1 * motorspeed; + if( motorspeed >= 255) motorspeed=255; + digitalWrite ( MotorIN2 , LOW ); + analogWrite ( MotorIN1, motorspeed ); + //digitalWrite ( MotorIN1 , HIGH ); + //analogWrite ( MotorIN2, 255 - motorspeed ); + } + } +} + +void doEncoderMotor0(){ + //if (((PIND&B0000100)>>2) == HIGH) { // found a low-to-high on channel A; if(digitalRead(encoderPinA)==HIGH){.... read PD2 (I2) + if(digitalRead(encoder0PinA)==HIGH){ + + if ((PINB&B0000001) == LOW) { // check channel B to see which way; if(digitalRead(encoderPinB)==LOW){.... read PB0 (I8) + // encoder is turning + encoder0Pos-- ; // CCW + } + else { + encoder0Pos++ ; // CW + } + } + else // found a high-to-low on channel A + { + if ((PINB&B0000001) == LOW) { // check channel B to see which way; if(digitalRead(encoderPinB)==LOW){.... read PB0 (I8) + // encoder is turning + encoder0Pos++ ; // CW + } + else { + encoder0Pos-- ; // CCW + } + + } + +} + +void countStep(){ + //dir=digitalRead(DIR_PIN)==HIGH; + dir = (PINC&B0000001); // dir=digitalRead(dir_pin) read PC0, 14 digital; + //here will be (PINB&B0000001) to not use shift in the stable version + if (dir) target1++; + else target1--; +} diff --git a/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_2/ServoStrapPortManipulationLD293D_1_2.ino b/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_2/ServoStrapPortManipulationLD293D_1_2.ino new file mode 100755 index 0000000..c281146 --- /dev/null +++ b/Moteur DC/ServoStrap/ServoStrapPortManipulationLD293D_1_2/ServoStrapPortManipulationLD293D_1_2.ino @@ -0,0 +1,229 @@ +#include +//this is to use DWF library, it will increase the speed of digitalRead/Write command +//used in the interrupt function doEncoderMotor0, but may be used everywhere. +/* +https://github.com/danithebest91/ServoStrap + i have made this code for the LMD18245 motor controller, + i have merged the pid code of Josh Kopel + whith the code of makerbot servo-controller board, + you can use this code on the some board changing some values. + Daniele Poddighe + external ardware require a quadrature encoder, timing slit strip and a dc motor, + all you can find inside an old printer, i have took it from canon and hp printers(psc1510) + + for motor controll you can choose different type of H-bridge, i have used LMD18245, + you can order 3 of it on ti.com sample request, the hardware needed is explained on the datasheet but i'm drowing + the schematic and PCB layout on eagle. + + + read a rotary encoder with interrupts + Encoder hooked up with common to GROUND, + encoder0PinA to pin 2, encoder0PinB to pin 4 (or pin 3 see below) + it doesn't matter which encoder pin you use for A or B + + is possible to change PID costants by sending on serial interfaces the values separated by ',' in this order: KP,KD,KI + example: 5.2,3.1,0 so we have KP=5.2 KD=3.1 KI=0 is only for testing purposes, but i will leave this function with eeprom storage + + This code use Port manipulation : + Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Arduino board. The chips used on the Arduino board + (the ATmega8 and ATmega168) have three ports: + B (digital pin 8 to 13) + C (analog input pins) + D (digital pins 0 to 7) + https://www.arduino.cc/en/Reference/PortManipulation + + https://www.arduino.cc/en/Hacking/PinMapping + https://www.arduino.cc/en/Hacking/PinMapping168 +*/ + +#define encoder0PinA 2 // PD2 (INT0) You can't modify port mapping here because this code use Port manipulation (I2) +#define encoder0PinB 8 // PB0; (I8) + +#define MotorIN1 5 //(I5) IN1 +#define MotorIN2 6 //(I6) IN2 + +//from ramps 1.4 stepper driver +#define STEP_PIN 3 //PD3 (INT1) (I3) +#define DIR_PIN 14 //PC0; (A0) +#define X_MIN 4 //(4) + +volatile long encoder0Pos = 0; + +long target = 0; +long target1 = 0; +int StartRoutine=0; +//correction = Kp * error + Kd * (error - prevError) + kI * (sum of errors) +//PID controller constants +float KP = 5 ; //position multiplier (gain) 2.25 +float KI = 0.1; // Intergral multiplier (gain) .25 +float KD = 2.0; // derivative multiplier (gain) 1.0 + +int lastError = 0; +int sumError = 0; + +//Integral term min/max (random value and not yet tested/verified) +int iMax = 100; +int iMin = 0; + +long previousTarget = 0; +long previousMillis = 0; // will store last time LED was updated +long interval = 5; // interval at which to blink (milliseconds) + +//for motor control ramps 1.4 +bool newStep = false; +bool oldStep = false; +bool dir = false; + +void setup() { + pinModeFast(2, INPUT); + pinModeFast(encoder0PinA, INPUT); + pinModeFast(encoder0PinB, INPUT); + pinModeFast(X_MIN, INPUT); + + + pinModeFast(MotorIN1, OUTPUT); + pinModeFast(MotorIN2, OUTPUT); + + //ramps 1.4 motor control + pinModeFast(STEP_PIN, INPUT); + pinModeFast(DIR_PIN, INPUT); + + attachInterrupt(0, doEncoderMotor0, CHANGE); // encoder pin on interrupt 0 - pin 2 + attachInterrupt(1, countStep, RISING); //on pin 3 + + Serial.begin (115200); + Serial.println("start"); // a personal quirk + +} + +void loop(){ + + while (Serial.available() > 0) { + KP = Serial.parseFloat(); + KD = Serial.parseFloat(); + KI = Serial.parseFloat(); + + + Serial.println(KP); + Serial.println(KD); + Serial.println(KI); +} + Fstart(); + if(millis() - previousTarget > 1000){ //enable this code only for test purposes because it loss a lot of time + +// if (X_MIN == LOW) Serial.print("LOW"); +// else Serial.print("HIGH"); +// Serial.print(','); + Serial.print(encoder0Pos); + Serial.print(','); + Serial.println(target1); + previousTarget=millis(); + } + + target = target1; + docalc(); +} + +void Fstart(){ + + if (StartRoutine == 0) + { + digitalWrite ( MotorIN1 , LOW ); + analogWrite ( MotorIN2, 200 ); + delay(2000); + digitalWrite ( MotorIN2 , LOW ); + analogWrite ( MotorIN1, 255 ); + delay(200); + digitalWrite ( MotorIN1, LOW ); + analogWrite ( MotorIN2, 255 ); + delay(180); + digitalWrite ( MotorIN2, LOW ); + analogWrite ( MotorIN1, 255 ); + delay(100); + digitalWrite ( MotorIN1, LOW ); + analogWrite ( MotorIN2, 255 ); + delay(90); + digitalWrite ( MotorIN2, LOW ); + analogWrite ( MotorIN1, 255 ); + delay(100); + digitalWrite ( MotorIN1, LOW ); + analogWrite ( MotorIN2, 200 ); + delay(2000); + + + StartRoutine = 1; + encoder0Pos=0; + } + +} + +void docalc() { + + if (millis() - previousMillis > interval) + { + previousMillis = millis(); + long error = encoder0Pos - target ; // find the error term of current position - target + + //generalized PID formula + //correction = Kp * error + Kd * (error - prevError) + kI * (sum of errors) + long motorspeed = KP * error + KD * (error - lastError) +KI * (sumError); + + lastError = error; + sumError += error; + + //scale the sum for the integral term + if(sumError > iMax) { + sumError = iMax; + } else if(sumError < iMin){ + sumError = iMin; + } + + if(motorspeed > 0){ + if( motorspeed >= 255) motorspeed=255; + digitalWrite ( MotorIN1 , LOW ); + analogWrite ( MotorIN2, motorspeed ); + } + if(motorspeed < 0){ + motorspeed = -1 * motorspeed; + if( motorspeed >= 255) motorspeed=255; + digitalWrite ( MotorIN2 , LOW ); + analogWrite ( MotorIN1, motorspeed ); + //digitalWrite ( MotorIN1 , HIGH ); + //analogWrite ( MotorIN2, 255 - motorspeed ); + } + } +} + +void doEncoderMotor0(){ + //if (((PIND&B0000100)>>2) == HIGH) { // found a low-to-high on channel A; if(digitalRead(encoderPinA)==HIGH){.... read PD2 (I2) + if(digitalRead(encoder0PinA)==HIGH){ + + if ((PINB&B0000001) == LOW) { // check channel B to see which way; if(digitalRead(encoderPinB)==LOW){.... read PB0 (I8) + // encoder is turning + encoder0Pos-- ; // CCW + } + else { + encoder0Pos++ ; // CW + } + } + else // found a high-to-low on channel A + { + if ((PINB&B0000001) == LOW) { // check channel B to see which way; if(digitalRead(encoderPinB)==LOW){.... read PB0 (I8) + // encoder is turning + encoder0Pos++ ; // CW + } + else { + encoder0Pos-- ; // CCW + } + + } + +} + +void countStep(){ + //dir=digitalRead(DIR_PIN)==HIGH; + dir = (PINC&B0000001); // dir=digitalRead(dir_pin) read PC0, 14 digital; + //here will be (PINB&B0000001) to not use shift in the stable version + if (dir) target1++; + else target1--; +} diff --git a/Moteur DC/ServoStrap/digitalWriteFast.h b/Moteur DC/ServoStrap/digitalWriteFast.h old mode 100644 new mode 100755 diff --git a/Moteur DC/ServoStrap/keywords.txt b/Moteur DC/ServoStrap/keywords.txt old mode 100644 new mode 100755 diff --git a/Moteur DC/Test/Test_Moteur_DC/Test_Moteur_DC.ino b/Moteur DC/Test/Test_Moteur_DC/Test_Moteur_DC.ino old mode 100644 new mode 100755 diff --git a/Moteur DC/Test/Test_Roue_Codeuse/Test_Roue_Codeuse.ino b/Moteur DC/Test/Test_Roue_Codeuse/Test_Roue_Codeuse.ino old mode 100644 new mode 100755 diff --git a/README b/README old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/Imprimante_3d_fablab.SLDASM b/imprimante_3d_fablab/Imprimante_3d_fablab.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/Boulon M6 hexa 30mm.SLDPRT b/imprimante_3d_fablab/pièces/Boulon M6 hexa 30mm.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/HeatingBed_214x214mm.SLDPRT b/imprimante_3d_fablab/pièces/HeatingBed_214x214mm.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/NORDEX-ABX-C3-8.SLDPRT b/imprimante_3d_fablab/pièces/NORDEX-ABX-C3-8.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/Rexroth-Default.SLDPRT b/imprimante_3d_fablab/pièces/Rexroth-Default.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/Tasseau M6.SLDPRT b/imprimante_3d_fablab/pièces/Tasseau M6.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/User Library-fan - pabst 512f.SLDPRT b/imprimante_3d_fablab/pièces/User Library-fan - pabst 512f.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/ZERO MAX-SC030R-SC030R - 5 mm x 8 mm_SC030R_A-1.sldprt b/imprimante_3d_fablab/pièces/ZERO MAX-SC030R-SC030R - 5 mm x 8 mm_SC030R_A-1.sldprt old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/axe charnière.SLDPRT b/imprimante_3d_fablab/pièces/axe charnière.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/batant charnière.SLDPRT b/imprimante_3d_fablab/pièces/batant charnière.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/eclisse_40x40x222_bisote_x1.SLDPRT b/imprimante_3d_fablab/pièces/eclisse_40x40x222_bisote_x1.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/eclisse_40x40x404_bisote_x2.SLDPRT b/imprimante_3d_fablab/pièces/eclisse_40x40x404_bisote_x2.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/eclisse_40x40x670_bisote_x1.SLDPRT b/imprimante_3d_fablab/pièces/eclisse_40x40x670_bisote_x1.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/eclisse_40x40x704_bisote_x2.SLDPRT b/imprimante_3d_fablab/pièces/eclisse_40x40x704_bisote_x2.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_acrylique_380x210.SLDPRT b/imprimante_3d_fablab/pièces/plaque_acrylique_380x210.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_acrylique_380x670.SLDPRT b/imprimante_3d_fablab/pièces/plaque_acrylique_380x670.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_acrylique_380x680.SLDPRT b/imprimante_3d_fablab/pièces/plaque_acrylique_380x680.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_acrylique_680x210.SLDPRT b/imprimante_3d_fablab/pièces/plaque_acrylique_680x210.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_acrylique_680x670.SLDPRT b/imprimante_3d_fablab/pièces/plaque_acrylique_680x670.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_acrylique_680x670_porte.SLDPRT b/imprimante_3d_fablab/pièces/plaque_acrylique_680x670_porte.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_repartition_aire_chaud_300x544mm.SLDPRT b/imprimante_3d_fablab/pièces/plaque_repartition_aire_chaud_300x544mm.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/plaque_verre_428x210mm.SLDPRT b/imprimante_3d_fablab/pièces/plaque_verre_428x210mm.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/porte.SLDPRT b/imprimante_3d_fablab/pièces/porte.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/prof_40x40x300mm.SLDPRT b/imprimante_3d_fablab/pièces/prof_40x40x300mm.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/prof_40x40x600mm.SLDPRT b/imprimante_3d_fablab/pièces/prof_40x40x600mm.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/support_moteur_chassis.SLDPRT b/imprimante_3d_fablab/pièces/support_moteur_chassis.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/support_plateau.SLDPRT b/imprimante_3d_fablab/pièces/support_plateau.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/pièces/volume_d_impression.SLDPRT b/imprimante_3d_fablab/pièces/volume_d_impression.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Base.SLDPRT b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Base.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Cuerpo.SLDPRT b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Cuerpo.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Eje.SLDPRT b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Eje.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17 with T5 Pulley.SLDASM b/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17 with T5 Pulley.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17 with T5 Pulley.STEP b/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17 with T5 Pulley.STEP old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17 with T5 Pulley.STP b/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17 with T5 Pulley.STP old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17+support.SLDASM b/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17+support.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17.SLDASM b/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17.STL b/imprimante_3d_fablab/sous_assemblages/NEMA 17/NEMA 17.STL old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA 17 with T5 Pulley Render.avi b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA 17 with T5 Pulley Render.avi old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA 17 with T5 Pulley Render.gif b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA 17 with T5 Pulley Render.gif old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA 17 with T5 Pulley.avi b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA 17 with T5 Pulley.avi old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA17 2.JPG b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA17 2.JPG old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA17 3.JPG b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA17 3.JPG old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA17 with T5 Pulley.JPG b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Renderings/NEMA17 with T5 Pulley.JPG old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/T5 Pulley.SLDPRT b/imprimante_3d_fablab/sous_assemblages/NEMA 17/T5 Pulley.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/Tapa.SLDPRT b/imprimante_3d_fablab/sous_assemblages/NEMA 17/Tapa.SLDPRT old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/NEMA 17/radial ball bearing_68_am.sldprt b/imprimante_3d_fablab/sous_assemblages/NEMA 17/radial ball bearing_68_am.sldprt old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/cadre_600x300mm.SLDASM b/imprimante_3d_fablab/sous_assemblages/cadre_600x300mm.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/carcasse.SLDASM b/imprimante_3d_fablab/sous_assemblages/carcasse.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/charniere.SLDASM b/imprimante_3d_fablab/sous_assemblages/charniere.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/couvercle.SLDASM b/imprimante_3d_fablab/sous_assemblages/couvercle.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/sous_assemblages/plateau_complet.SLDASM b/imprimante_3d_fablab/sous_assemblages/plateau_complet.SLDASM old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/vue_carcasse+plateau_16.11.2015.png b/imprimante_3d_fablab/vue_carcasse+plateau_16.11.2015.png old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/vue_carcasse+volume_impression_13.11.2015.png b/imprimante_3d_fablab/vue_carcasse+volume_impression_13.11.2015.png old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/vue_carcasse_13.11.2015.png b/imprimante_3d_fablab/vue_carcasse_13.11.2015.png old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/vue_carcasse_prof_only_16.11.2015.png b/imprimante_3d_fablab/vue_carcasse_prof_only_16.11.2015.png old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/vue_dessu_cotes_pour_core_XY_16.11.2015.png b/imprimante_3d_fablab/vue_dessu_cotes_pour_core_XY_16.11.2015.png old mode 100644 new mode 100755 diff --git a/imprimante_3d_fablab/vue_plateau_15.11.2015.png b/imprimante_3d_fablab/vue_plateau_15.11.2015.png old mode 100644 new mode 100755