Skip to content
Snippets Groups Projects
Commit 1e0ceefd authored by Kyrre Ness Sjobaek's avatar Kyrre Ness Sjobaek
Browse files

Merge branch 'config_pins_fixes' into 'master'

Config pins fixes

See merge request !2
parents a110a417 d0fca551
Branches
No related tags found
1 merge request!2Config pins fixes
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
//Note on Arduino pins used for Ethernet shield, //Note on Arduino pins used for Ethernet shield,
// AVOID THESE PINS: // AVOID THESE PINS:
// 4/10/11/12/13 (UNO) // 4/10/11/12/13 (UNO)
// 50/51/52/10/4 (Mega) // 50/51/52/10/4; 53 unused but it MUST be an output (Mega)
// ***** HARDWARE SIMULATION (FOR DEV) ********* // ***** HARDWARE SIMULATION (FOR DEV) *********
//Uncomment to simulate hardware //Uncomment to simulate hardware
#define DUMMY_TEMP //#define DUMMY_TEMP
#define DUMMY_SERVO //#define DUMMY_SERVO
#define DUMMY_STEPPER //#define DUMMY_STEPPER
// ***** NETWORK CONFIG ************************ // ***** NETWORK CONFIG ************************
...@@ -27,7 +27,10 @@ ...@@ -27,7 +27,10 @@
//byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x84, 0xEE}; //byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x84, 0xEE};
// MAC address for Kyrre's test board // MAC address for Kyrre's test board
byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x72, 0xF7}; //byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x72, 0xF7};
// MAC address for the Arduino on the 4DRobot
byte mac[] = {0xA8, 0x61, 0x0A, 0xAE, 0x84, 0xEF};
//To use DHCP or not to use DHCP, that's the question. //To use DHCP or not to use DHCP, that's the question.
// Comment out to use static IP configuration // Comment out to use static IP configuration
...@@ -53,14 +56,15 @@ const size_t output_bufflen = 2048; ...@@ -53,14 +56,15 @@ const size_t output_bufflen = 2048;
// ***** TEMPERATURE SENSOR CONFIG ************* // ***** TEMPERATURE SENSOR CONFIG *************
const uint8_t temp_oneWire_pin = 51; // <-- Conflict with ETHERNET! const uint8_t temp_oneWire_pin = 49;
const size_t temp_numSensors = 1; const size_t temp_numSensors = 1;
const unsigned long temp_update_interval = 1000; //[ms] const unsigned long temp_update_interval = 1000; //[ms]
// ***** SAMPLE GRABBER SERVO CONFIG *********** // ***** SAMPLE GRABBER SERVO CONFIG ***********
// TODO: Tune stepWait, positions // TODO: Tune stepWait, positions
const int grabber_servo_pin = 9; // Note: Servo may prefer pin 9 (PWM)?
const int grabber_servo_pin = 47;
const int grabber_closed = 86; //[deg] const int grabber_closed = 86; //[deg]
const int grabber_open = 130; //[deg] const int grabber_open = 130; //[deg]
const int grabber_min = 0; //[deg] const int grabber_min = 0; //[deg]
...@@ -78,8 +82,8 @@ const size_t stepper_numAxis = 3; ...@@ -78,8 +82,8 @@ const size_t stepper_numAxis = 3;
const char stepper_axnames[] = {'X','Y','Z'}; const char stepper_axnames[] = {'X','Y','Z'};
const uint8_t stepper_dir_pin[] = {32,36,40}; //Stepper direction pins (HIGH=positive, LOW=negative) const uint8_t stepper_dir_pin[] = {6,9,12}; //Stepper direction pins (HIGH=positive, LOW=negative)
const uint8_t stepper_step_pin[] = {33,37,41}; //Stepper pulse-to-step pins (pulse HIGH, otherwise low) const uint8_t stepper_step_pin[] = {5,8,11}; //Stepper pulse-to-step pins (pulse HIGH, otherwise low)
//Define level for stepper_dir_pin[] to count steps in forward direction //Define level for stepper_dir_pin[] to count steps in forward direction
// Used to define the Z axis as zero when on top, so that we can zero it first on top switch, // Used to define the Z axis as zero when on top, so that we can zero it first on top switch,
...@@ -90,8 +94,8 @@ const bool stepper_backward[] = {HIGH,LOW,LOW}; ...@@ -90,8 +94,8 @@ const bool stepper_backward[] = {HIGH,LOW,LOW};
//TODO: PIN4 ALSO IN USE BY ETHERNET //TODO: PIN4 ALSO IN USE BY ETHERNET
//TODO: Verify reproducibility of zeroing, we may need debounce? //TODO: Verify reproducibility of zeroing, we may need debounce?
const uint8_t stepper_switchMAX_pin[] = {2,5,7}; //positive steps limit switch pins const uint8_t stepper_switchMAX_pin[] = {33,37,41}; //positive steps limit switch pins
const uint8_t stepper_switchMIN_pin[] = {3,4,6}; //negative steps limit switch pins const uint8_t stepper_switchMIN_pin[] = {32,36,40}; //negative steps limit switch pins
//TODO: Verify active/inactive -> HIGH/LOW //TODO: Verify active/inactive -> HIGH/LOW
// Note: Needs pulldown/pullup resistor // Note: Needs pulldown/pullup resistor
// Note: Probably safest to define on-limit = open, so if a switch fails the axis is safe (but stopped) // Note: Probably safest to define on-limit = open, so if a switch fails the axis is safe (but stopped)
......
...@@ -48,6 +48,8 @@ bool stepper_go_zero = false; //Move-to-position (fa ...@@ -48,6 +48,8 @@ bool stepper_go_zero = false; //Move-to-position (fa
size_t stepper_go_axis = 0; //Which stepper to move? size_t stepper_go_axis = 0; //Which stepper to move?
long int stepper_goto = 0; //[steps] Target position long int stepper_goto = 0; //[steps] Target position
// (used if stepper_go_zero==false) // (used if stepper_go_zero==false)
bool stepper_interlock = true; //Is the stepper interlock enabled (safe)
// or disabled (unsafe)?
long int stepper_pos[] = {0,0,0}; //Current stepper position long int stepper_pos[] = {0,0,0}; //Current stepper position
bool stepper_mode_absolute[] = {false,false,false}; //Do we have a valid zeroing? bool stepper_mode_absolute[] = {false,false,false}; //Do we have a valid zeroing?
// If true, pos represents the absolute // If true, pos represents the absolute
......
...@@ -403,23 +403,24 @@ bool parse_line(char* line_buff) { ...@@ -403,23 +403,24 @@ bool parse_line(char* line_buff) {
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< USAGE:\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< USAGE:\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'HELP' : Get help\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'HELP' : Get help\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'TEMP' : Get temperature(s)\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'TEMP' : Get temperature(s)\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER STATUS' : Get grabber status\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER STATUS' : Get grabber status\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER POS int' : Goto the given position (integer)\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER POS int' : Goto the given position (integer)\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER CLOSE' : Close the grabber (goto POS = ")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER CLOSE' : Close the grabber (goto POS = "));
snprintf(buff, sizeof(buff), "%03d )\n", grabber_closed); snprintf(buff, sizeof(buff), "%03d )\n", grabber_closed);
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, buff); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, buff);
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER OPEN' : Open the grabber (goto POS = ")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'GRABBER OPEN' : Open the grabber (goto POS = "));
snprintf(buff, sizeof(buff), "%03d )\n", grabber_open); snprintf(buff, sizeof(buff), "%03d )\n", grabber_open);
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, buff); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, buff);
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER STATUS' : Get the stepper status\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER STATUS' : Get the stepper status\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER POS <axis> <steps>' : Goto the given position on the given axis\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER POS <axis> <steps>' : Goto the given position on the given axis\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER ZEROSEEK <axis>' : Find the zero on the given axis (enables absolute mode)\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER ZEROSEEK <axis>' : Find the zero on the given axis (enables absolute mode)\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER RESET <axis>' : Resets the given axis (sets position to 0 and disables absolute mode)\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER RESET <axis>' : Resets the given axis (sets position to 0 and disables absolute mode)\n"));
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< 'STEPPER INTERLOCK ENABLE/DISABLE : Enable/disable the lockout of XY until Z is in absolute and above minimum\n"));
} }
...@@ -509,6 +510,12 @@ bool parse_line(char* line_buff) { ...@@ -509,6 +510,12 @@ bool parse_line(char* line_buff) {
else if (len >= 7 and strncmp(line_buff, "STEPPER", 7)==0) { else if (len >= 7 and strncmp(line_buff, "STEPPER", 7)==0) {
if (len >= 14 and strncmp(line_buff+7, " STATUS", 7)==0) { //'STEPPER STATUS' if (len >= 14 and strncmp(line_buff+7, " STATUS", 7)==0) { //'STEPPER STATUS'
if (stepper_interlock) {
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER INTERLOCK ENABLED (SAFE)\n"));
}
else {
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER INTERLOCK DISABLED (UNSAFE)\n"));
}
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER AX POS ABS MIN MAX\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER AX POS ABS MIN MAX\n"));
//Print "< STEPPER <X/Y/Z> <POS> <ABS> <MIN> <MAX>" //Print "< STEPPER <X/Y/Z> <POS> <ABS> <MIN> <MAX>"
for (size_t i=0; i<stepper_numAxis; i++) { for (size_t i=0; i<stepper_numAxis; i++) {
...@@ -591,10 +598,20 @@ bool parse_line(char* line_buff) { ...@@ -591,10 +598,20 @@ bool parse_line(char* line_buff) {
stepper_pos[tmpAx] = 0L; stepper_pos[tmpAx] = 0L;
stepper_mode_absolute[tmpAx] = false; stepper_mode_absolute[tmpAx] = false;
} }
else if (len >= 24 and strncmp(line_buff+7, " INTERLOCK ENABLE", 17) == 0) { // 'STEPPER INTERLOCK ENABLE'
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER INTERLOCK NOW ENABLED (SAFE)\n"));
stepper_interlock = true;
}
else if (len >= 25 and strncmp(line_buff+7, " INTERLOCK DISABLE", 18) == 0) { // 'STEPPER INTERLOCK DISABLE'
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER INTERLOCK NOW DISABLED (UNSAFE)\n"));
stepper_interlock = false;
}
else { else {
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< ERROR STEPPER COMMAND NOT RECOGNIZED\n")); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< ERROR STEPPER COMMAND NOT RECOGNIZED\n"));
} }
} }
else { else {
......
...@@ -12,6 +12,11 @@ void setup_servo() { ...@@ -12,6 +12,11 @@ void setup_servo() {
delay(1); delay(1);
} }
} }
//Initialize Servo library
#ifndef DUMMY_SERVO
grabber_servo.attach(grabber_servo_pin);
#endif
} }
//Program for controlling the servomotor for the grabber //Program for controlling the servomotor for the grabber
......
...@@ -22,8 +22,13 @@ void stepper_control() { ...@@ -22,8 +22,13 @@ void stepper_control() {
) )
) { ) {
//We are trying to move a locked axis //We are trying to move a locked axis
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER ERROR XY INTERLOCK\n")); if (stepper_interlock) {
goto resetGO; bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER ERROR XY INTERLOCK\n"));
goto resetGO;
}
else {
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, F("< STEPPER WARNING XY INTERLOCK IGNORED\n"));
}
} }
//Move! //Move!
...@@ -36,7 +41,7 @@ void stepper_control() { ...@@ -36,7 +41,7 @@ void stepper_control() {
if (stepper_go_zero) { if (stepper_go_zero) {
//Always move in negative direction when zeroing //Always move in negative direction when zeroing
digitalWrite(stepper_go_axis, stepper_backward[stepper_go_axis]); digitalWrite(stepper_dir_pin[stepper_go_axis], stepper_backward[stepper_go_axis]);
//Move until we trigger the low interlock switch //Move until we trigger the low interlock switch
bool onMAX = (digitalRead(stepper_switchMAX_pin[stepper_go_axis]) == stepper_switch_active); bool onMAX = (digitalRead(stepper_switchMAX_pin[stepper_go_axis]) == stepper_switch_active);
...@@ -54,9 +59,9 @@ void stepper_control() { ...@@ -54,9 +59,9 @@ void stepper_control() {
} }
//Move (slowly) //Move (slowly)
digitalWrite(stepper_go_axis,HIGH); digitalWrite(stepper_step_pin[stepper_go_axis],HIGH);
delayMicroseconds(stepper_onTime); delayMicroseconds(stepper_onTime);
digitalWrite(stepper_go_axis,LOW); digitalWrite(stepper_step_pin[stepper_go_axis],LOW);
delayMicroseconds(stepper_delay_slow); delayMicroseconds(stepper_delay_slow);
stepper_pos[stepper_go_axis] -= 1L; stepper_pos[stepper_go_axis] -= 1L;
...@@ -80,11 +85,11 @@ void stepper_control() { ...@@ -80,11 +85,11 @@ void stepper_control() {
else { else {
int stepping = 0; int stepping = 0;
if (stepper_goto > stepper_pos[stepper_go_axis]) { if (stepper_goto > stepper_pos[stepper_go_axis]) {
digitalWrite(stepper_go_axis, stepper_forward[stepper_go_axis]); digitalWrite(stepper_dir_pin[stepper_go_axis], stepper_forward[stepper_go_axis]);
stepping = 1; stepping = 1;
} }
else if(stepper_goto < stepper_pos[stepper_go_axis]) { else if(stepper_goto < stepper_pos[stepper_go_axis]) {
digitalWrite(stepper_go_axis, stepper_backward[stepper_go_axis]); digitalWrite(stepper_dir_pin[stepper_go_axis], stepper_backward[stepper_go_axis]);
stepping = -1; stepping = -1;
} }
// Note: No 'else' needed; if they are equal, the while loop doesn't iterate. // Note: No 'else' needed; if they are equal, the while loop doesn't iterate.
...@@ -107,9 +112,9 @@ void stepper_control() { ...@@ -107,9 +112,9 @@ void stepper_control() {
//Move (slowly) //Move (slowly)
//TODO: Implement acceleration //TODO: Implement acceleration
digitalWrite(stepper_go_axis,HIGH); digitalWrite(stepper_step_pin[stepper_go_axis],HIGH);
delayMicroseconds(stepper_onTime); delayMicroseconds(stepper_onTime);
digitalWrite(stepper_go_axis,LOW); digitalWrite(stepper_step_pin[stepper_go_axis],LOW);
delayMicroseconds(stepper_delay_slow); delayMicroseconds(stepper_delay_slow);
stepper_pos[stepper_go_axis] += stepping; stepper_pos[stepper_go_axis] += stepping;
...@@ -133,6 +138,9 @@ void stepper_control() { ...@@ -133,6 +138,9 @@ void stepper_control() {
snprintf(buff,sizeof(buff), "%+011ld\n",stepper_pos[stepper_go_axis]); snprintf(buff,sizeof(buff), "%+011ld\n",stepper_pos[stepper_go_axis]);
bufferWrite(output_buff, sizeof(output_buff), output_buffCount, buff); bufferWrite(output_buff, sizeof(output_buff), output_buffCount, buff);
digitalWrite(stepper_step_pin[stepper_go_axis],LOW);
digitalWrite(stepper_dir_pin[stepper_go_axis], LOW);
stepper_go = false; stepper_go = false;
stepper_go_zero = false; stepper_go_zero = false;
stepper_go_axis = 0; stepper_go_axis = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment