Add header
Add a header to explain the code
This commit is contained in:
@@ -1,12 +1,56 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
Titre : OpenCR
|
Title : OpenCR
|
||||||
Date : 6 février 2019
|
Date : April 10th 2019
|
||||||
Auteur : Maxime Desmarais-Laporte
|
Authors : Maxime Desmarais-Laporte and Marc-Antoine Lafreniere
|
||||||
|
|
||||||
Descritpion :
|
Descritpion :
|
||||||
|
GCode interpretor, use in a PCB maker device.
|
||||||
|
|
||||||
|
The device has 3 limits switches (one for every axis) use for a homing of the device
|
||||||
|
These switches are attach to one interrupt and to 3 digital pins.
|
||||||
|
The interrupt was noizy so a filter is apply to the interrupt
|
||||||
|
|
||||||
|
|
||||||
|
Interrupt filter :
|
||||||
|
To filter the noize on the interrupt we use the digital pin connected to the NC of the switch
|
||||||
|
The filter simply looks if the digital pin is LOW for *debounceTimeFalling* time
|
||||||
|
If it stays LOW for the whole *debounceTimeFalling* then a flag is set to true
|
||||||
|
If it stays HIGH for the whole *debounceTimeRising* then a flag is set to false
|
||||||
|
|
||||||
|
GCode status :
|
||||||
|
G0 Xx Yy Zz Done
|
||||||
|
G28 Done
|
||||||
|
G90 Inactive
|
||||||
|
G91 Not implemeted
|
||||||
|
M18 Done
|
||||||
|
M112 Done
|
||||||
|
|
||||||
|
Commincations :
|
||||||
|
When a command is recived, "2" is printed to the Serial port
|
||||||
|
When the command is done executing, "1" is printed to the Serial port
|
||||||
|
|
||||||
|
If the command can't complete, "-1" is printed to the Serial port
|
||||||
|
If the device is in eStop mode, "-2" is printed to the Serial port on a commmand request
|
||||||
|
|
||||||
|
|
||||||
|
Electrical :
|
||||||
|
The 3 homing switches are connected the same way :
|
||||||
|
NC to a digital pin
|
||||||
|
NO to the interrupt
|
||||||
|
COM to the ground
|
||||||
|
Hence every digital and interrupt pin MUST be in INPUT_PULLUP
|
||||||
|
|
||||||
|
|
||||||
|
TODO :
|
||||||
|
Connect 2 switches on the other end of the X and Y axis as a fail-safe and add a filter if needed
|
||||||
|
Change some variable usage : at the moment everything works only if motors' ids are +1 between each (ex: x=9, y=10, z=11)
|
||||||
|
|
||||||
Specifications :
|
Specifications :
|
||||||
Baud for motors : 57600 b/s
|
Baud for motors : 57600 b/s
|
||||||
Adress for motors : 11 and 12 and 13
|
|
||||||
|
Dynamixel and OpenCR documentation :
|
||||||
|
http://emanual.robotis.com/docs/en/dxl/x/xm430-w350/
|
||||||
|
http://emanual.robotis.com/docs/en/parts/controller/opencr10/
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#include <DynamixelWorkbench.h>
|
#include <DynamixelWorkbench.h>
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
@@ -16,34 +60,31 @@ Adress for motors : 11 and 12 and 13
|
|||||||
#define DEVICE_NAME "3"
|
#define DEVICE_NAME "3"
|
||||||
#elif defined(__OPENCR__)
|
#elif defined(__OPENCR__)
|
||||||
#define DEVICE_NAME ""
|
#define DEVICE_NAME ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STRING_BUF_NUM 64
|
#define STRING_BUF_NUM 64
|
||||||
#define MINTICK 0
|
#define MINTICK 0
|
||||||
#define MAXTICK 1048575
|
#define MAXTICK 1048575
|
||||||
const int ACCEPTABLE_RANGE[3] = { 2, 2, 3 };
|
const int ACCEPTABLE_RANGE[3] = { 2, 2, 4 };
|
||||||
|
|
||||||
// 0 = not reverse, 1 = reverse
|
|
||||||
uint8_t X_REVERSE = 0;
|
|
||||||
uint8_t Y_REVERSE = 1;
|
|
||||||
uint8_t Z_REVERSE = 0;
|
|
||||||
|
|
||||||
const String HOMING_OFFSET = "Homing_Offset";
|
const String HOMING_OFFSET = "Homing_Offset";
|
||||||
const String OPERATING_MODE = "Operating_Mode";
|
const String OPERATING_MODE = "Operating_Mode";
|
||||||
const String PRESENT_POSITION = "Present_Position";
|
const String PRESENT_POSITION = "Present_Position";
|
||||||
const String GOAL_POSITION = "Goal_Position";
|
const String GOAL_POSITION = "Goal_Position";
|
||||||
|
|
||||||
String cmd[STRING_BUF_NUM];
|
// 0 = not reverse, 1 = reverse
|
||||||
|
uint8_t X_REVERSE = 0;
|
||||||
|
uint8_t Y_REVERSE = 1;
|
||||||
|
uint8_t Z_REVERSE = 0;
|
||||||
|
|
||||||
|
// Dynamixel variables
|
||||||
DynamixelWorkbench dxl_wb;
|
DynamixelWorkbench dxl_wb;
|
||||||
|
String cmd[STRING_BUF_NUM];
|
||||||
uint8_t get_id[16];
|
uint8_t get_id[16];
|
||||||
uint8_t scan_cnt = 0;
|
uint8_t scan_cnt = 0;
|
||||||
uint8_t ping_cnt = 0;
|
uint8_t ping_cnt = 0;
|
||||||
|
|
||||||
const char *NULL_POINTER = NULL;
|
const char *NULL_POINTER = NULL;
|
||||||
|
|
||||||
bool isEmegencyState = false;
|
|
||||||
|
|
||||||
// Motors Propertys :
|
// Motors Propertys :
|
||||||
uint8_t idX = 11;
|
uint8_t idX = 11;
|
||||||
uint8_t idY = 12;
|
uint8_t idY = 12;
|
||||||
@@ -69,8 +110,8 @@ bool homingY = false;
|
|||||||
bool homingZ = false;
|
bool homingZ = false;
|
||||||
int homingState = 0;
|
int homingState = 0;
|
||||||
|
|
||||||
const int homeOffsetX = /*28*/50*tickFromMm;
|
const int homeOffsetX = 28*tickFromMm;
|
||||||
const int homeOffsetY = /*19.5*/50*tickFromMm;
|
const int homeOffsetY = 19.5*tickFromMm;
|
||||||
const int homeOffsetZ = 2.5*tickFromMm;
|
const int homeOffsetZ = 2.5*tickFromMm;
|
||||||
|
|
||||||
// Debounce timer variables
|
// Debounce timer variables
|
||||||
@@ -91,6 +132,7 @@ bool isYSwitchPress = false;
|
|||||||
bool isZSwitchPress = false;
|
bool isZSwitchPress = false;
|
||||||
|
|
||||||
// eStop
|
// eStop
|
||||||
|
bool isEmegencyState = false;
|
||||||
bool ledX = false;
|
bool ledX = false;
|
||||||
bool ledY = false;
|
bool ledY = false;
|
||||||
bool ledZ = false;
|
bool ledZ = false;
|
||||||
@@ -105,7 +147,6 @@ int32_t currentPosition = 0;
|
|||||||
int32_t movingSpeed[] = { 75, 75 };
|
int32_t movingSpeed[] = { 75, 75 };
|
||||||
MovingCommand commands[3];
|
MovingCommand commands[3];
|
||||||
|
|
||||||
// Initialisation :
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// Initialisation des pins :
|
// Initialisation des pins :
|
||||||
@@ -152,7 +193,6 @@ void setup()
|
|||||||
resetMovingVariables();
|
resetMovingVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main Program
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if(isFalling)
|
if(isFalling)
|
||||||
@@ -165,6 +205,7 @@ void loop()
|
|||||||
isFalling = false;
|
isFalling = false;
|
||||||
isXSwitchPress = true;
|
isXSwitchPress = true;
|
||||||
|
|
||||||
|
// Insert what to do if the button is press (executed on change)
|
||||||
if(homingX)
|
if(homingX)
|
||||||
{
|
{
|
||||||
homingX = false;
|
homingX = false;
|
||||||
@@ -201,6 +242,7 @@ void loop()
|
|||||||
isFalling = false;
|
isFalling = false;
|
||||||
isYSwitchPress = true;
|
isYSwitchPress = true;
|
||||||
|
|
||||||
|
// Insert what to do if the button is press (executed on change)
|
||||||
if(homingY)
|
if(homingY)
|
||||||
{
|
{
|
||||||
homingY = false;
|
homingY = false;
|
||||||
@@ -237,6 +279,7 @@ void loop()
|
|||||||
isFalling = false;
|
isFalling = false;
|
||||||
isZSwitchPress = true;
|
isZSwitchPress = true;
|
||||||
|
|
||||||
|
// Insert what to do if the button is press (executed on change)
|
||||||
if(homingZ)
|
if(homingZ)
|
||||||
{
|
{
|
||||||
homingZ = false;
|
homingZ = false;
|
||||||
@@ -278,6 +321,7 @@ void loop()
|
|||||||
lastTimeXRising = millis();
|
lastTimeXRising = millis();
|
||||||
isRising = false;
|
isRising = false;
|
||||||
isXSwitchPress = false;
|
isXSwitchPress = false;
|
||||||
|
// Insert what to do if the button is release (executed on change)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -290,6 +334,7 @@ void loop()
|
|||||||
lastTimeYRising = millis();
|
lastTimeYRising = millis();
|
||||||
isRising = false;
|
isRising = false;
|
||||||
isYSwitchPress = false;
|
isYSwitchPress = false;
|
||||||
|
// Insert what to do if the button is release (executed on change)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -302,6 +347,7 @@ void loop()
|
|||||||
lastTimeZRising = millis();
|
lastTimeZRising = millis();
|
||||||
isRising = false;
|
isRising = false;
|
||||||
isZSwitchPress = false;
|
isZSwitchPress = false;
|
||||||
|
// Insert what to do if the button is release (executed on change)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -446,17 +492,6 @@ void loop()
|
|||||||
|
|
||||||
Serial.println("1");
|
Serial.println("1");
|
||||||
}
|
}
|
||||||
else if(words[0] == "M1")
|
|
||||||
{
|
|
||||||
TorqueOffAll();
|
|
||||||
|
|
||||||
Write(idX, -Read(idX, PRESENT_POSITION), HOMING_OFFSET);
|
|
||||||
Write(idY, -Read(idY, PRESENT_POSITION), HOMING_OFFSET);
|
|
||||||
Write(idZ, -Read(idZ, PRESENT_POSITION), HOMING_OFFSET);
|
|
||||||
|
|
||||||
TorqueOnAll();
|
|
||||||
Serial.println("1");
|
|
||||||
}
|
|
||||||
else if(words[0] == "G90")
|
else if(words[0] == "G90")
|
||||||
{
|
{
|
||||||
Serial.println("1");
|
Serial.println("1");
|
||||||
@@ -549,7 +584,6 @@ void setEmergency()
|
|||||||
void changeMode(uint8_t id)
|
void changeMode(uint8_t id)
|
||||||
{
|
{
|
||||||
Write(id, 4, OPERATING_MODE);
|
Write(id, 4, OPERATING_MODE);
|
||||||
//Write(id, movingSpeed[id-idX], "Profile_Velocity");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user