2024-09-06 13:33:19 +00:00
|
|
|
#include "definitions.h"
|
|
|
|
#include "vacuum.h"
|
|
|
|
#include "servo.h"
|
2024-09-11 09:40:46 +00:00
|
|
|
#include "bodytemp.h"
|
|
|
|
#include "behaviour.h"
|
2024-09-06 13:33:19 +00:00
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
2024-09-10 09:44:19 +00:00
|
|
|
pinMode(PIN_VIBRATION,OUTPUT);
|
|
|
|
analogWrite(PIN_VIBRATION,0);
|
|
|
|
|
2024-09-06 13:33:19 +00:00
|
|
|
pinMode(PIN_BUTTON,INPUT_PULLDOWN);
|
2024-09-11 09:40:46 +00:00
|
|
|
pinMode(PIN_LED,OUTPUT);
|
|
|
|
digitalWrite(PIN_LED,HIGH); //LOW=Light, HIGH=Off
|
2024-09-06 13:33:19 +00:00
|
|
|
|
|
|
|
initVacuum();
|
2024-09-11 09:40:46 +00:00
|
|
|
initBodytemp();
|
2024-09-06 13:33:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
pinMode(PIN_INPUTARM1,INPUT);
|
2024-09-11 09:40:46 +00:00
|
|
|
pinMode(PIN_INPUTARM2,INPUT);
|
|
|
|
pinMode(PIN_INPUTARM3,INPUT);
|
2024-09-06 14:51:50 +00:00
|
|
|
|
2024-09-10 09:44:19 +00:00
|
|
|
pinMode(PIN_INPUTAUX,INPUT);
|
|
|
|
|
2024-09-06 14:51:50 +00:00
|
|
|
initServos();
|
2024-09-06 13:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
unsigned long loopmillis=millis();
|
2024-09-11 09:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool body_present=checkBodypresence(loopmillis);
|
|
|
|
digitalWrite(PIN_LED,!body_present);
|
2024-09-06 13:33:19 +00:00
|
|
|
|
|
|
|
loopVacuum(loopmillis);
|
|
|
|
|
2024-09-11 09:40:46 +00:00
|
|
|
|
|
|
|
bool buttonstate=digitalRead(PIN_BUTTON); //Temporary Vacuum Button. HIGH=Pressed
|
|
|
|
if (buttonstate) { //Button pressed
|
|
|
|
setVacuum(false); //release
|
|
|
|
}else{
|
|
|
|
setVacuum(body_present);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool contact_main=digitalRead(PIN_INPUTARM1); //Sensor on tip of arm
|
|
|
|
|
|
|
|
updateMatrixWeights(loopmillis,body_present,contact_main);
|
|
|
|
updateServosByWeights(loopmillis);
|
|
|
|
|
2024-09-06 14:51:50 +00:00
|
|
|
loopServos(loopmillis);
|
|
|
|
|
2024-09-06 13:33:19 +00:00
|
|
|
|
2024-09-11 09:40:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-06 13:33:19 +00:00
|
|
|
//Print Debug Information
|
|
|
|
static unsigned long last_print=0;
|
|
|
|
if (loopmillis - last_print >100) {
|
|
|
|
last_print=loopmillis;
|
2024-09-06 14:51:50 +00:00
|
|
|
//printVacuumValues();
|
|
|
|
//Serial.print(" Vac="); Serial.print(vac);
|
|
|
|
|
|
|
|
printServoDebug();
|
2024-09-11 09:40:46 +00:00
|
|
|
Serial.println();
|
|
|
|
//printBodytempDebug();
|
|
|
|
|
2024-09-06 14:51:50 +00:00
|
|
|
|
2024-09-06 13:33:19 +00:00
|
|
|
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|