Takeup WIP

This commit is contained in:
Matt McWilliams 2022-11-15 21:39:31 -05:00
parent a5907409ca
commit 6060381e95
2 changed files with 123 additions and 26 deletions

View File

@ -9,6 +9,15 @@ ARM_CUTOFF = 101.25;
ARMS_ANGLE = 40; ARMS_ANGLE = 40;
module original_takeup () {
module block () {
cube([105, 26.8, 5.9], center = true);
cube([105, 36.6, 5.9], center = true);
}
block();
}
module projector_mount () { module projector_mount () {
//intersection () {} //intersection () {}
$fn = 60; $fn = 60;
@ -39,4 +48,6 @@ rotate([0, 0, ARMS_ANGLE]) {
rotate([0, 0, -ARMS_ANGLE]) { rotate([0, 0, -ARMS_ANGLE]) {
translate([ARM_LENGTH/2, 0, 2.75]) projector_arm(); translate([ARM_LENGTH/2, 0, 2.75]) projector_arm();
translate([ARM_LENGTH, 0, 5.5]) projector_mount(); translate([ARM_LENGTH, 0, 5.5]) projector_mount();
} }
color("red") original_takeup();

View File

@ -1,58 +1,144 @@
/** /**
* Prototype * Prototype
* Arduino Duemilanove * Arduino Uno
* L298N shield V03 * L298N
* https://traction-design.be/home/arduino-l298n-shield-v03-from-flamingoeda-com/
*
* Pin 13 = motor A or coil A +
* Pin 12 = motor A or coil A
* Pin 11 = motor B or coil B +
* Pin 10 = motor A or coil A enable
* Pin 9 = motor B or coil B enable
* Pin 8 = motor B or coil B
**/ **/
#define Apos 9 #define Apos 9
#define Aneg 10 #define Aneg 10
#define Aenable 10
#define Bpos 5
#define Bneg 6
volatile int Aspeed = 255;
volatile int Bspeed = 255;
volatile boolean Arunning = false;
volatile boolean Brunning = false;
void setup() { void setup() {
Serial.begin(57600);
Serial.println("Started takeup demo");
pinMode(Apos, OUTPUT); pinMode(Apos, OUTPUT);
pinMode(Aneg, OUTPUT); pinMode(Aneg, OUTPUT);
pinMode(Aenable, OUTPUT); pinMode(Bpos, OUTPUT);
pinMode(Bneg, OUTPUT);
} }
void loop() { void loop() {
clockwise(); clockwise(0);
set_speed(250); counter_clockwise(1);
set_speed(0, 255);
set_speed(1, 255);
delay(5000); delay(5000);
brake(); brake();
delay(2000); delay(2000);
counter_clockwise(); counter_clockwise(0);
set_speed(250); clockwise(1);
set_speed(0, 150);
set_speed(1, 150);
delay(5000); delay(5000);
brake(); brake();
delay(2000); delay(2000);
} }
//input value from 0 to 255 //input value from 0 to 255
void set_speed (int val){ void set_speed (int motor, int val){
analogWrite(Aenable, val); if (motor == 0) {
Aspeed = val;
} else if (motor == 1) {
Bspeed = val;
}
} }
void clockwise(){ void clockwise_fade (int motor, int startSpeed, int stopSpeed, int ms) {
digitalWrite(Apos, HIGH); int steps = ceil((float) ms / (float) abs(stopSpeed - startSpeed));
digitalWrite(Aneg, LOW); int stepMs = round((float) ms / (float) steps);
int motorSpeed = startSpeed;
for (int i = 0; i < steps; i++) {
if (motor == 0) {
analogWrite(Apos, motorSpeed);
analogWrite(Aneg, 0);
Arunning = true;
} else if (motor == 1) {
analogWrite(Bpos, motorSpeed);
analogWrite(Bneg, 0);
Brunning = true;
}
delay(stepMs);
motorSpeed += stopSpeed > startSpeed ? 1 : -1;
}
if (motor == 0) {
Aspeed = stopSpeed;
} else if (motor == 1) {
Bspeed = stopSpeed;
}
} }
void counter_clockwise(){ void counter_clockwise_fade (int motor, int startSpeed, int stopSpeed, int ms) {
digitalWrite(Apos, LOW); int steps = ceil((float) ms / (float) abs(stopSpeed - startSpeed));
digitalWrite(Aneg, HIGH); int stepMs = round((float) ms / (float) steps);
int motorSpeed = startSpeed;
if (motor == 0) {
analogWrite(Apos, 0);
} else if (motor == 1) {
analogWrite(Bpos, 0);
}
for (int i = 0; i < steps; i++) {
if (motor == 0) {
analogWrite(Aneg, motorSpeed);
Arunning = true;
} else if (motor == 1) {
analogWrite(Bneg, motorSpeed);
Brunning = true;
}
delay(stepMs);
motorSpeed += stopSpeed > startSpeed ? 1 : -1;
}
if (motor == 0) {
Aspeed = stopSpeed;
} else if (motor == 1) {
Bspeed = stopSpeed;
}
}
void clockwise (int motor){
if (motor == 0) {
analogWrite(Apos, Aspeed);
analogWrite(Aneg, 0);
Arunning = true;
} else if (motor == 1) {
analogWrite(Bpos, Bspeed);
analogWrite(Bneg, 0);
Brunning = true;
}
}
void counter_clockwise (int motor){
if (motor == 0) {
analogWrite(Apos, 0);
analogWrite(Aneg, Aspeed);
Arunning = true;
} else if (motor == 1) {
analogWrite(Bpos, 0);
analogWrite(Bneg, Bspeed);
Brunning = true;
}
} }
void brake (){ void brake (){
digitalWrite(Aenable, LOW); if (Arunning) {
digitalWrite(Apos, LOW);
digitalWrite(Aneg, LOW);
Arunning = false;
}
if (Brunning) {
digitalWrite(Bpos, LOW);
digitalWrite(Bneg, LOW);
Brunning = false;
}
} }
/** /**