mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-03 03:13:25 +02:00
Fixed issue with trinamic ganged axes
This commit is contained in:
@@ -175,7 +175,8 @@
|
||||
#define DEFAULT_Z_MAX_TRAVEL 10.0 // This is percent in servo mode
|
||||
*/
|
||||
|
||||
// SPI 4 axis xyza
|
||||
/*
|
||||
// ======================= SPI 4 axis xyza ===========================
|
||||
#define MACHINE_NAME "MotorClass Test 4x SPI XYZA"
|
||||
#define N_AXIS 4
|
||||
|
||||
@@ -210,3 +211,43 @@
|
||||
#define A_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
|
||||
|
||||
#define SPINDLE_TYPE SPINDLE_TYPE_NONE
|
||||
*/
|
||||
|
||||
// ======================= SPI 4 axis xxyz ===========================
|
||||
#define MACHINE_NAME "MotorClass Test 4x SPI XXYZ"
|
||||
#define N_AXIS 3
|
||||
|
||||
#define TRINAMIC_DAISY_CHAIN
|
||||
|
||||
// Use SPI enable instead of the enable pin
|
||||
// The hardware enable pin is tied to ground
|
||||
#define USE_TRINAMIC_ENABLE
|
||||
|
||||
#define X_TRINAMIC_DRIVER 2130
|
||||
#define X_RSENSE TMC2130_RSENSE_DEFAULT
|
||||
#define X_STEP_PIN GPIO_NUM_12
|
||||
#define X_DIRECTION_PIN GPIO_NUM_14
|
||||
#define X_CS_PIN GPIO_NUM_17 // Daisy Chain, all share same CS pin
|
||||
|
||||
#define X2_TRINAMIC_DRIVER 2130
|
||||
#define X2_RSENSE TMC2130_RSENSE_DEFAULT
|
||||
#define X2_STEP_PIN GPIO_NUM_27
|
||||
#define X2_DIRECTION_PIN GPIO_NUM_26
|
||||
#define X2_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
|
||||
//#define X_AXIS_SQUARING
|
||||
|
||||
#define Y_TRINAMIC_DRIVER 2130
|
||||
#define Y_RSENSE TMC2130_RSENSE_DEFAULT
|
||||
#define Y_STEP_PIN GPIO_NUM_15
|
||||
#define Y_DIRECTION_PIN GPIO_NUM_2
|
||||
#define Y_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
|
||||
|
||||
|
||||
#define Z_TRINAMIC_DRIVER 2130
|
||||
#define Z_RSENSE TMC2130_RSENSE_DEFAULT
|
||||
#define Z_STEP_PIN GPIO_NUM_33
|
||||
#define Z_DIRECTION_PIN GPIO_NUM_32
|
||||
#define Z_CS_PIN X_CS_PIN // Daisy Chain, all share same CS pin
|
||||
|
||||
#define SPINDLE_TYPE SPINDLE_TYPE_NONE
|
||||
|
||||
|
@@ -186,9 +186,9 @@ void init_motors() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
for (uint8_t gang_index = 0; gang_index < 2; gang_index++) {
|
||||
for (uint8_t axis = X_AXIS; axis < N_AXIS; axis++) {
|
||||
myMotor[axis][gang_index]->test();
|
||||
for (uint8_t axis = X_AXIS; axis < N_AXIS; axis++) {
|
||||
for (uint8_t gang_index = 0; gang_index < 2; gang_index++) {
|
||||
myMotor[axis][gang_index]->test();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,6 +342,19 @@ void Motor :: set_direction_pins(uint8_t onMask) {}
|
||||
void Motor :: step(uint8_t step_mask, uint8_t dir_mask) {}
|
||||
bool Motor :: test() {return true;}; // true = OK
|
||||
|
||||
void Motor :: set_axis_name() {
|
||||
char ganged[3];
|
||||
|
||||
if (dual_axis_index) {
|
||||
strcpy(ganged, "2");
|
||||
} else {
|
||||
strcpy(ganged, "");
|
||||
}
|
||||
|
||||
sprintf(_axis_name, "%c%s", report_get_axis_letter(axis_index), ganged);
|
||||
|
||||
}
|
||||
|
||||
void Motor :: set_homing_mode(bool is_homing) {
|
||||
_is_homing = is_homing;
|
||||
}
|
||||
|
@@ -63,6 +63,22 @@ extern uint8_t rmt_chan_num[MAX_AXES][2];
|
||||
extern rmt_item32_t rmtItem[2];
|
||||
extern rmt_config_t rmtConfig;
|
||||
|
||||
// ========== global functions ===================
|
||||
|
||||
// These are used for setup and to talk to the motors as a group.
|
||||
void init_motors();
|
||||
uint8_t get_next_trinamic_driver_index();
|
||||
void readSgTask(void* pvParameters);
|
||||
void motor_read_settings();
|
||||
void motors_set_homing_mode(bool is_homing);
|
||||
void motors_set_disable(bool disable);
|
||||
void motors_set_direction_pins(uint8_t onMask);
|
||||
void motors_step(uint8_t step_mask, uint8_t dir_mask);
|
||||
|
||||
extern bool motor_class_steps; // true if at least one motor class is handling steps
|
||||
|
||||
// ==================== Classes ====================
|
||||
|
||||
class Motor {
|
||||
public:
|
||||
Motor();
|
||||
@@ -76,12 +92,19 @@ class Motor {
|
||||
virtual void set_direction_pins(uint8_t onMask);
|
||||
virtual void step(uint8_t step_mask, uint8_t dir_mask); // only used on Unipolar right now
|
||||
virtual bool test();
|
||||
virtual void set_axis_name();
|
||||
|
||||
uint8_t axis_index; // X_AXIS, etc
|
||||
uint8_t dual_axis_index; // 0 = primary 1=ganged
|
||||
uint8_t is_active = false;
|
||||
|
||||
|
||||
|
||||
|
||||
bool _is_homing;
|
||||
|
||||
char _axis_name[10];
|
||||
|
||||
};
|
||||
|
||||
class Nullmotor : public Motor {
|
||||
@@ -151,18 +174,5 @@ class UnipolarMotor : public Motor {
|
||||
|
||||
|
||||
|
||||
// ========== global functions ===================
|
||||
|
||||
// These are used for setup and to talk to the motors as a group.
|
||||
void init_motors();
|
||||
uint8_t get_next_trinamic_driver_index();
|
||||
void readSgTask(void* pvParameters);
|
||||
void motor_read_settings();
|
||||
void motors_set_homing_mode(bool is_homing);
|
||||
void motors_set_disable(bool disable);
|
||||
void motors_set_direction_pins(uint8_t onMask);
|
||||
void motors_step(uint8_t step_mask, uint8_t dir_mask);
|
||||
|
||||
extern bool motor_class_steps; // true if at least one motor class is handling steps
|
||||
|
||||
#endif
|
@@ -30,7 +30,7 @@ TrinamicDriver :: TrinamicDriver( uint8_t axis_index,
|
||||
uint16_t driver_part_number,
|
||||
float r_sense, uint8_t cs_pin,
|
||||
int8_t spi_index) {
|
||||
this->axis_index = axis_index;
|
||||
this->axis_index = axis_index % MAX_AXES;
|
||||
this->dual_axis_index = axis_index < 6 ? 0 : 1; // 0 = primary 1 = ganged
|
||||
_driver_part_number = driver_part_number;
|
||||
_r_sense = r_sense;
|
||||
@@ -50,6 +50,7 @@ void TrinamicDriver :: init() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "Trinamic unsupported p/n:%d", _driver_part_number);
|
||||
return;
|
||||
}
|
||||
set_axis_name();
|
||||
config_message();
|
||||
// TODO step pins
|
||||
init_step_dir_pins(); // from StandardStepper
|
||||
@@ -65,28 +66,28 @@ void TrinamicDriver :: init() {
|
||||
/*
|
||||
This is the startup message showing the basic definition
|
||||
*/
|
||||
void TrinamicDriver :: config_message() {
|
||||
void TrinamicDriver :: config_message() {
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"%c Axis Trinamic driver TMC%d Step:%d Dir:%d CS:%d Index:%d",
|
||||
report_get_axis_letter(axis_index),
|
||||
"%s Axis Trinamic driver TMC%d Step:%d Dir:%d CS:%d Index:%d",
|
||||
_axis_name,
|
||||
_driver_part_number,
|
||||
step_pin,
|
||||
dir_pin,
|
||||
cs_pin,
|
||||
cs_pin,
|
||||
spi_index);
|
||||
}
|
||||
|
||||
bool TrinamicDriver :: test() {
|
||||
bool TrinamicDriver :: test() {
|
||||
switch (tmcstepper->test_connection()) {
|
||||
case 1:
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%c Trinamic driver test failed. Check connection", report_get_axis_letter(axis_index));
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Trinamic driver test failed. Check connection", _axis_name);
|
||||
return false;
|
||||
case 2:
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%c Trinamic driver test failed. Check motor power", report_get_axis_letter(axis_index));
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Trinamic driver test failed. Check motor power", _axis_name);
|
||||
return false;
|
||||
default:
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%c Trinamic driver test passed", report_get_axis_letter(axis_index));
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Trinamic driver test passed", _axis_name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -97,10 +98,10 @@ bool TrinamicDriver :: test() {
|
||||
void TrinamicDriver :: trinamic_test_response() {
|
||||
switch (tmcstepper->test_connection()) {
|
||||
case 1:
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%c Trinamic driver test failed. Check connection", report_get_axis_letter(axis_index));
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Trinamic driver test failed. Check connection", _axis_name);
|
||||
break;
|
||||
case 2:
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%c Trinamic driver test failed. Check motor power", report_get_axis_letter(axis_index));
|
||||
grbl_msg_sendf(CLIENT_SERIAL, MSG_LEVEL_INFO, "%s Trinamic driver test failed. Check motor power", _axis_name);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
@@ -178,8 +179,8 @@ void TrinamicDriver :: set_mode() {
|
||||
|
||||
grbl_msg_sendf(CLIENT_SERIAL,
|
||||
MSG_LEVEL_INFO,
|
||||
"%c Stallguard %d SG_Val: %04d Rate: %05.0fmm/min, %d",
|
||||
report_get_axis_letter(axis_index),
|
||||
"%s Stallguard %d SG_Val: %04d Rate: %05.0fmm/min, %d",
|
||||
_axis_name,
|
||||
tmcstepper->stallguard(),
|
||||
tmcstepper->sg_result(),
|
||||
feedrate,
|
||||
|
Reference in New Issue
Block a user