CAN Probe configuration

This commit is contained in:
matthew wildoer
2017-11-08 17:03:31 +11:00
parent f761e065d5
commit e0ee9b2048
5 changed files with 58 additions and 53 deletions
+12 -12
View File
@@ -15,41 +15,41 @@ void can_message_received (uint32_t id, uint8_t length, uint8_t* data) {
case CAN_GPIO_INPUT_ADDRESS_1: can_gpio_received(0, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_2
case CAN_GPIO_INPUT_ADDRESS_2: can_gpio_received(2, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_2: can_gpio_received(1, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_3
case CAN_GPIO_INPUT_ADDRESS_3: can_gpio_received(3, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_3: can_gpio_received(2, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_4
case CAN_GPIO_INPUT_ADDRESS_4: can_gpio_received(4, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_4: can_gpio_received(3, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_5
case CAN_GPIO_INPUT_ADDRESS_5: can_gpio_received(5, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_5: can_gpio_received(4, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_6
case CAN_GPIO_INPUT_ADDRESS_6: can_gpio_received(6, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_6: can_gpio_received(5, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_7
case CAN_GPIO_INPUT_ADDRESS_7: can_gpio_received(7, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_7: can_gpio_received(6, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_8
case CAN_GPIO_INPUT_ADDRESS_8: can_gpio_received(8, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_8: can_gpio_received(7, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_9
case CAN_GPIO_INPUT_ADDRESS_9: can_gpio_received(9, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_9: can_gpio_received(8, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_10
case CAN_GPIO_INPUT_ADDRESS_10: can_gpio_received(10, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_10: can_gpio_received(9, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_11
case CAN_GPIO_INPUT_ADDRESS_11: can_gpio_received(11, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_11: can_gpio_received(10, 1, data); break;
#endif
#ifdef CAN_GPIO_INPUT_ADDRESS_12
case CAN_GPIO_INPUT_ADDRESS_12: can_gpio_received(12, length, data); break;
case CAN_GPIO_INPUT_ADDRESS_12: can_gpio_received(11, 1, data); break;
#endif
}
//can_gpio_received(100, 1, data);
}
+34 -32
View File
@@ -86,8 +86,8 @@ static void _motion_end_callback(float* vect, bool* flag)
/***********************************************************************************
* cm_probing_cycle_start() - G38.x probing cycle using contact (digital input)
*
* cm_probe_cycle_start() is the entry point for a probe cycle. It checks for
* some errors, sets up the cycle, then prevents any new commands from queuing
* cm_probe_cycle_start() is the entry point for a probe cycle. It checks for
* some errors, sets up the cycle, then prevents any new commands from queuing
* to the planner so that the planner can move to a stop and report motion stopped.
*
* --- Some further details ---
@@ -110,12 +110,12 @@ static void _motion_end_callback(float* vect, bool* flag)
* PROBE_SUCCEEDED, then we roll 0 to 1, and 1 to 2, up to PROBES_STORED-1.
* The oldest probe is "lost."
*
* Alarms and exceptions: It is *not* necessarily an error condition for the
* probe not to trigger, depending on the G38.x command received. It is an error
* Alarms and exceptions: It is *not* necessarily an error condition for the
* probe not to trigger, depending on the G38.x command received. It is an error
* for the limit or homing switches to fire, or for some other configuration error.
* These are trapped and cause Alarms.
*
* Note: Spindle and coolant are not affected during probing. Some probes require
*
* Note: Spindle and coolant are not affected during probing. Some probes require
* the spindle to be turned on.
*
* Note: When coding a cycle (like this one) you get to perform one queued
@@ -124,15 +124,15 @@ static void _motion_end_callback(float* vect, bool* flag)
* sets a flag in the probing object (pb.waiting_for_motion_end) to tell us that
* the move has finished. The runtime has a special exception for probing and
* homing where if a move is interrupted it clears it out of the queue.
*
* You must also wait until the last move has actually completed before declaring
* the cycle to be done. Otherwise there is a nasty race condition in the
* _controller_HSM() that may accept the next command before the position of the
* final move has been recorded in the Gcode model. That's part of what what the
*
* You must also wait until the last move has actually completed before declaring
* the cycle to be done. Otherwise there is a nasty race condition in the
* _controller_HSM() that may accept the next command before the position of the
* final move has been recorded in the Gcode model. That's part of what what the
* wait_for_motion_end callback is about.
*/
uint8_t cm_straight_probe(float target[], bool flags[], bool trip_sense, bool alarm_flag)
uint8_t cm_straight_probe(float target[], bool flags[], bool trip_sense, bool alarm_flag)
{
// error if zero feed rate
if (fp_ZERO(cm.gm.feed_rate)) {
@@ -150,6 +150,8 @@ uint8_t cm_straight_probe(float target[], bool flags[], bool trip_sense, bool al
return(cm_alarm(STAT_NO_PROBE_INPUT_CONFIGURED, "No probe input"));
}
// setup
pb.alarm_flag = alarm_flag; // set true to enable probe fail alarms (all exceptions alarm regardless)
pb.trip_sense = trip_sense; // set to sense of "tripped" contact
@@ -163,8 +165,8 @@ uint8_t cm_straight_probe(float target[], bool flags[], bool trip_sense, bool al
if (cm.probe_state[0] == PROBE_SUCCEEDED) {
for (uint8_t n = PROBES_STORED - 1; n > 0; n--) {
cm.probe_state[n] = cm.probe_state[n - 1];
for (uint8_t axis = 0; axis < AXES; axis++) {
cm.probe_results[n][axis] = cm.probe_results[n - 1][axis];
for (uint8_t axis = 0; axis < AXES; axis++) {
cm.probe_results[n][axis] = cm.probe_results[n - 1][axis];
}
}
}
@@ -176,19 +178,19 @@ uint8_t cm_straight_probe(float target[], bool flags[], bool trip_sense, bool al
pb.wait_for_motion_end = true;
mp_queue_command(_motion_end_callback, nullptr, nullptr); // note: these args are ignored
return (STAT_OK);
}
}
/***********************************************************************************
* cm_probing_cycle_callback() - handle probing progress
*
* This is called regularly from the controller. If we report NOOP, the controller
* will continue with other tasks. Otherwise the controller will not execute any
* This is called regularly from the controller. If we report NOOP, the controller
* will continue with other tasks. Otherwise the controller will not execute any
* later tasks, including read any more "data".
*/
uint8_t cm_probing_cycle_callback(void)
uint8_t cm_probing_cycle_callback(void)
{
if ((cm.cycle_state != CYCLE_PROBE) && (cm.probe_state[0] != PROBE_WAITING)) {
if ((cm.cycle_state != CYCLE_PROBE) && (cm.probe_state[0] != PROBE_WAITING)) {
return (STAT_NOOP); // exit if not in a probing cycle
}
if (pb.wait_for_motion_end) { // sync to planner move ends (using callback)
@@ -201,14 +203,14 @@ uint8_t cm_probing_cycle_callback(void)
* _probing_start() - start the probe or skip it if contact is already active
*/
static uint8_t _probing_start()
static uint8_t _probing_start()
{
// so optimistic... ;)
// These initializations are required before starting the probing cycle but must
// be done after the planner has exhausted all current moves as they affect the
// runtime (specifically the digital input modes). Side effects would include
// be done after the planner has exhausted all current moves as they affect the
// runtime (specifically the digital input modes). Side effects would include
// limit switches initiating probe actions instead of just killing movement
cm.probe_state[0] = PROBE_FAILED;
cm.machine_state = MACHINE_CYCLE;
cm.cycle_state = CYCLE_PROBE;
@@ -218,7 +220,7 @@ static uint8_t _probing_start()
pb.saved_units_mode = (cmUnitsMode)cm_get_units_mode(ACTIVE_MODEL);
pb.saved_soft_limits = cm_get_soft_limits();
cm_set_soft_limits(false);
// set working values
cm_set_distance_mode(ABSOLUTE_DISTANCE_MODE);
cm_set_units_mode(MILLIMETERS);
@@ -242,7 +244,7 @@ static uint8_t _probing_start()
return(_probing_exception_exit(STAT_PROBE_IS_ALREADY_TRIPPED));
}
// Everything checks out. Run the probe move
// Everything checks out. Run the probe move
_probe_move(pb.target, pb.flags);
pb.func = _probing_backoff;
return (STAT_EAGAIN);
@@ -254,10 +256,10 @@ static uint8_t _probing_start()
* Back off to the measured touch position captured by encoder snapshot
*/
static stat_t _probing_backoff()
static stat_t _probing_backoff()
{
// Test if we've contacted. If so, do the backoff. Convert the contact position
// captured from the encoder in step space to steps to mm. The encoder snapshot
// Test if we've contacted. If so, do the backoff. Convert the contact position
// captured from the encoder in step space to steps to mm. The encoder snapshot
// was taken by input interrupt at the time of closure.
if (pb.trip_sense == gpio_read_input(pb.probe_input)) { // exclusive or for booleans
@@ -281,7 +283,7 @@ static stat_t _probing_backoff()
static stat_t _probe_move(const float target[], const bool flags[])
{
cm_set_absolute_override(MODEL, ABSOLUTE_OVERRIDE_ON);
cm_set_absolute_override(MODEL, ABSOLUTE_OVERRIDE_ON);
pb.wait_for_motion_end = true; // set this BEFORE the motion starts
cm_straight_feed(target, flags);
mp_queue_command(_motion_end_callback, nullptr, nullptr); // the last two arguments are ignored anyway
@@ -294,12 +296,12 @@ static stat_t _probe_move(const float target[], const bool flags[])
* _probing_finish() - exit for successful and non-contacted (failed) probes
*/
static void _probe_restore_settings()
static void _probe_restore_settings()
{
gpio_set_probing_mode(pb.probe_input, false); // set input back to normal operation
for (uint8_t axis = 0; axis < AXES; axis++) { // restore axis jerks
cm.a[axis].jerk_max = pb.saved_jerk[axis];
cm.a[axis].jerk_max = pb.saved_jerk[axis];
}
cm_set_absolute_override(MODEL, ABSOLUTE_OVERRIDE_OFF); // release abs override and restore work offsets
cm_set_distance_mode(pb.saved_distance_mode);
@@ -325,7 +327,7 @@ static stat_t _probing_finish()
for (uint8_t axis = 0; axis < AXES; axis++) {
cm.probe_results[0][axis] = cm_get_absolute_position(ACTIVE_MODEL, axis);
}
// handle failed probes - successful probes already set the flag
if (cm.probe_state[0] == PROBE_FAILED) {
if (pb.alarm_flag) {
+6 -4
View File
@@ -228,9 +228,9 @@ struct ioDigitalInputVirtual {
return false;
}
/*bool pin_value = (bool)input_pin;
int8_t pin_value_corrected = (pin_value ^ ((int)in->mode ^ 1)); // correct for NO or NC mode
in->state = (ioState)pin_value_corrected;*/
// bool pin_value = (bool)input_pin;
// int8_t pin_value_corrected = (pin_value ^ ((int)in->mode ^ 1)); // correct for NO or NC mode
in->state = INPUT_INACTIVE;
return true;
}
@@ -383,7 +383,7 @@ void can_gpio_received (int pin_num, uint8_t length, uint8_t* data) {
bool pin_value=false;
if (data[0] > 0) pin_value=true;
printf("%i/n", pin_num);
_vdin[pin_num].pin_changed(pin_value);
}
@@ -628,6 +628,8 @@ void gpio_set_probing_mode(const uint8_t input_num_ext, const bool is_probing)
int8_t gpio_get_probing_input(void)
{
//inputs_reset();
for (uint8_t i = 0; i <= D_IN_CHANNELS+D_IN_CAN_CHANNELS; i++) {
if (d_in[i-1].function == INPUT_FUNCTION_PROBE) {
return (i);
+1 -1
View File
@@ -40,7 +40,7 @@
#define A_OUT_CHANNELS 0 // number of analog outputs supported
// #ifndef D_IN_CAN_CHANNELS
#define D_IN_CAN_CHANNELS 1
#define D_IN_CAN_CHANNELS 2
// #endif
#ifndef D_OUT_CAN_CHANNELS
#define D_OUT_CAN_CHANNELS 0
+5 -4
View File
@@ -205,6 +205,7 @@
//*****************************************************************************
#define CAN_GPIO_INPUT_ADDRESS_1 0xA1
#define CAN_GPIO_INPUT_ADDRESS_2 0x42
//#define D_IN_CAN_CHANNELS 0
//*****************************************************************************
@@ -731,13 +732,13 @@
// Zmin
#ifndef DI5_MODE
#define DI5_MODE IO_ACTIVE_LOW
#define DI5_MODE IO_MODE_DISABLED
#endif
#ifndef DI5_ACTION
#define DI5_ACTION INPUT_ACTION_STOP
#define DI5_ACTION INPUT_ACTION_NONE
#endif
#ifndef DI5_FUNCTION
#define DI5_FUNCTION INPUT_FUNCTION_PROBE
#define DI5_FUNCTION INPUT_FUNCTION_NONE
#endif
// Zmax
@@ -781,7 +782,7 @@
#define DI9_ACTION INPUT_ACTION_STOP
#endif
#ifndef DI9_FUNCTION
#define DI9_FUNCTION INPUT_FUNCTION_PROBE
#define DI9_FUNCTION INPUT_FUNCTION_NONE
#endif
#ifndef DI10_MODE