Merge in 9 months of work on capper branch #71

Merged
mattmcw merged 95 commits from capper into main 2023-02-19 05:28:46 +00:00
1 changed files with 34 additions and 12 deletions
Showing only changes of commit 28dc19fc32 - Show all commits

View File

@ -1,6 +1,6 @@
#include <Servo.h> #include <Servo.h>
boolean debug_state = false; boolean debug_state = true;
/* /*
---------------------------------------------------- ----------------------------------------------------
@ -24,6 +24,7 @@ Yellow - Pin 10
//Arduino Duemilanove //Arduino Duemilanove
const int PIN_SERVO = 9; const int PIN_SERVO = 9;
const int PIN_ENDSTOP = 10; const int PIN_ENDSTOP = 10;
const int PIN_ENDSTOP_PWR = 11;
volatile boolean running = false; volatile boolean running = false;
volatile boolean cap_state = false; volatile boolean cap_state = false;
@ -81,9 +82,9 @@ void cmd (char val) {
} else if (val == cmd_mcopy_identifier) { } else if (val == cmd_mcopy_identifier) {
identify(); identify();
} else if (val == cmd_cap_on) { } else if (val == cmd_cap_on) {
Cap_on(false); Cap_on(false, false);
} else if (val == cmd_cap_off) { } else if (val == cmd_cap_off) {
Cap_off(false); Cap_off(false, false);
} }
} }
@ -105,18 +106,29 @@ void identify () {
void Pins_init () { void Pins_init () {
pinMode(PIN_ENDSTOP, INPUT_PULLUP); pinMode(PIN_ENDSTOP, INPUT_PULLUP);
pinMode(PIN_ENDSTOP_PWR, OUTPUT);
Endstop_on();
} }
void Servo_init () { void Servo_init () {
servo.attach(PIN_SERVO); servo.attach(PIN_SERVO);
Cap_off(true); Cap_off(true, true);
/*if (!Read_endstop()) {
Cap_off(true);
}*/
} }
boolean Read_endstop () { boolean Read_endstop () {
return digitalRead(PIN_ENDSTOP) != LOW; endstop_state = digitalRead(PIN_ENDSTOP) != LOW;
log(endstop_state);
return endstop_state;
}
void Endstop_on () {
digitalWrite(PIN_ENDSTOP_PWR, HIGH);
delay(1);
}
void Endstop_off () {
digitalWrite(PIN_ENDSTOP_PWR, LOW);
delay(1);
} }
void Servo_angle (int newAngle) { void Servo_angle (int newAngle) {
@ -130,28 +142,38 @@ int Servo_delay (int angleA, int angleB) {
return (int) ceil((float) angle * servoSpeed); return (int) ceil((float) angle * servoSpeed);
} }
void Cap_off (boolean suppress) { void Cap_off (boolean suppress, boolean force) {
Endstop_on();
current_angle = servo.read(); current_angle = servo.read();
if (cap_state || current_angle != cap_off_angle) { if ((Read_endstop() || force) && (cap_state || current_angle != cap_off_angle)) {
Servo_angle(cap_off_angle); Servo_angle(cap_off_angle);
cap_state = false; cap_state = false;
} else { } else {
log("Cap already off"); log("Cap already off");
} }
while (Read_endstop()) {
delay(1);
}
Endstop_off();
log("Cap_off()"); log("Cap_off()");
if (!suppress) { if (!suppress) {
Serial.println(cmd_cap_off); Serial.println(cmd_cap_off);
} }
} }
void Cap_on (boolean suppress) { void Cap_on (boolean suppress, boolean force) {
Endstop_on();
current_angle = servo.read(); current_angle = servo.read();
if (!cap_state || current_angle != cap_on_angle) { if ((!Read_endstop() || force) && (!cap_state || current_angle != cap_on_angle)) {
Servo_angle(cap_on_angle); Servo_angle(cap_on_angle);
cap_state = true; cap_state = true;
} else { } else {
log("Cap already on"); log("Cap already on");
} }
while (!Read_endstop()) {
delay(1);
}
Endstop_off();
log("Cap_on()"); log("Cap_on()");
if (!suppress) { if (!suppress) {
Serial.println(cmd_cap_on); Serial.println(cmd_cap_on);