mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-31 10:01:48 +02:00
Applied UART configurable to TrinamicUart
This commit is contained in:
@@ -31,7 +31,7 @@
|
|||||||
#include "../Limits.h" // limitsMinPosition
|
#include "../Limits.h" // limitsMinPosition
|
||||||
|
|
||||||
namespace Motors {
|
namespace Motors {
|
||||||
bool Motors::Dynamixel2::uart_ready = false;
|
bool Motors::Dynamixel2::_uart_started = false;
|
||||||
uint8_t Motors::Dynamixel2::ids[MAX_N_AXIS][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
|
uint8_t Motors::Dynamixel2::ids[MAX_N_AXIS][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
|
||||||
|
|
||||||
void Dynamixel2::init() {
|
void Dynamixel2::init() {
|
||||||
@@ -40,7 +40,7 @@ namespace Motors {
|
|||||||
|
|
||||||
ids[_axis_index][dual_axis_index()] = _id; // learn all the ids
|
ids[_axis_index][dual_axis_index()] = _id; // learn all the ids
|
||||||
|
|
||||||
if (!uart_ready) {
|
if (!_uart_started) {
|
||||||
if (_uart->baud != 1000000) {
|
if (_uart->baud != 1000000) {
|
||||||
info_serial("Warning: The baud rate is %d. Dynamixels typically use 1000000 baud.");
|
info_serial("Warning: The baud rate is %d. Dynamixels typically use 1000000 baud.");
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ namespace Motors {
|
|||||||
info_serial("Dynamixel:");
|
info_serial("Dynamixel:");
|
||||||
_uart->config_message();
|
_uart->config_message();
|
||||||
|
|
||||||
uart_ready = true;
|
_uart_started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_settings();
|
read_settings();
|
||||||
|
@@ -62,7 +62,7 @@ namespace Motors {
|
|||||||
|
|
||||||
Uart* _uart = nullptr;
|
Uart* _uart = nullptr;
|
||||||
|
|
||||||
static const int DYNAMIXEL_BAUD_RATE = 1000000;
|
static bool _uart_started;
|
||||||
|
|
||||||
static const int DXL_RESPONSE_WAIT_TICKS = 20; // how long to wait for a response
|
static const int DXL_RESPONSE_WAIT_TICKS = 20; // how long to wait for a response
|
||||||
|
|
||||||
@@ -114,7 +114,6 @@ namespace Motors {
|
|||||||
void set_disable(bool disable) override;
|
void set_disable(bool disable) override;
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
static bool uart_ready;
|
|
||||||
static uint8_t ids[MAX_N_AXIS][2];
|
static uint8_t ids[MAX_N_AXIS][2];
|
||||||
|
|
||||||
// Configuration handlers:
|
// Configuration handlers:
|
||||||
|
@@ -32,8 +32,6 @@
|
|||||||
#include <TMCStepper.h> // https://github.com/teemuatlut/TMCStepper
|
#include <TMCStepper.h> // https://github.com/teemuatlut/TMCStepper
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
Uart tmc_serial(TMC_UART);
|
|
||||||
|
|
||||||
namespace Motors {
|
namespace Motors {
|
||||||
|
|
||||||
bool TrinamicUartDriver::_uart_started = false;
|
bool TrinamicUartDriver::_uart_started = false;
|
||||||
@@ -43,10 +41,9 @@ namespace Motors {
|
|||||||
|
|
||||||
void TrinamicUartDriver::init() {
|
void TrinamicUartDriver::init() {
|
||||||
if (!_uart_started) {
|
if (!_uart_started) {
|
||||||
#ifdef LATER
|
_uart->begin();
|
||||||
tmc_serial.setPins(TMC_UART_TX, TMC_UART_RX);
|
info_serial("Trinamic:");
|
||||||
#endif
|
_uart->config_message();
|
||||||
tmc_serial.begin(115200, UartData::Bits8, UartStop::Bits1, UartParity::None);
|
|
||||||
_uart_started = true;
|
_uart_started = true;
|
||||||
}
|
}
|
||||||
_has_errors = hw_serial_init();
|
_has_errors = hw_serial_init();
|
||||||
@@ -89,7 +86,7 @@ namespace Motors {
|
|||||||
|
|
||||||
bool TrinamicUartDriver::hw_serial_init() {
|
bool TrinamicUartDriver::hw_serial_init() {
|
||||||
if (_driver_part_number == 2209) {
|
if (_driver_part_number == 2209) {
|
||||||
tmcstepper = new TMC2209Stepper(&tmc_serial, _r_sense, _addr);
|
tmcstepper = new TMC2209Stepper(_uart, _r_sense, _addr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
info_serial("Unsupported Trinamic motor p/n:%d", _driver_part_number);
|
info_serial("Unsupported Trinamic motor p/n:%d", _driver_part_number);
|
||||||
@@ -100,20 +97,12 @@ namespace Motors {
|
|||||||
This is the startup message showing the basic definition.
|
This is the startup message showing the basic definition.
|
||||||
*/
|
*/
|
||||||
void TrinamicUartDriver::config_message() { //TODO: The RX/TX pin could be added to the msg.
|
void TrinamicUartDriver::config_message() { //TODO: The RX/TX pin could be added to the msg.
|
||||||
info_serial("%s motor Trinamic TMC%d Step:%s Dir:%s Disable:%s UART%d Rx:%s Tx:%s Addr:%d R:%0.3f %s",
|
info_serial("%s motor Trinamic TMC%d Step:%s Dir:%s Disable:%s Addr:%d R:%0.3f %s",
|
||||||
reportAxisNameMsg(axis_index(), dual_axis_index()),
|
reportAxisNameMsg(axis_index(), dual_axis_index()),
|
||||||
_driver_part_number,
|
_driver_part_number,
|
||||||
_step_pin.name().c_str(),
|
_step_pin.name().c_str(),
|
||||||
_dir_pin.name().c_str(),
|
_dir_pin.name().c_str(),
|
||||||
_disable_pin.name().c_str(),
|
_disable_pin.name().c_str(),
|
||||||
TMC_UART,
|
|
||||||
#ifdef LATER
|
|
||||||
pinName(TMC_UART_RX),
|
|
||||||
pinName(TMC_UART_TX),
|
|
||||||
#else
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
#endif
|
|
||||||
_addr,
|
_addr,
|
||||||
_r_sense,
|
_r_sense,
|
||||||
reportAxisLimitsMsg(axis_index()));
|
reportAxisLimitsMsg(axis_index()));
|
||||||
|
@@ -25,31 +25,14 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
const float TMC2208_RSENSE_DEFAULT = 0.11f;
|
|
||||||
const float TMC2209_RSENSE_DEFAULT = 0.11f;
|
|
||||||
|
|
||||||
#ifndef TMC_UART
|
|
||||||
# define TMC_UART UART_NUM_2
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LATER
|
|
||||||
# ifndef TMC_UART_RX
|
|
||||||
# define TMC_UART_RX UNDEFINED_PIN
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifndef TMC_UART_TX
|
|
||||||
# define TMC_UART_TX UNDEFINED_PIN
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class TMC2209Stepper; // Forward declaration
|
class TMC2209Stepper; // Forward declaration
|
||||||
|
|
||||||
extern Uart tmc_serial;
|
|
||||||
|
|
||||||
namespace Motors {
|
namespace Motors {
|
||||||
|
|
||||||
class TrinamicUartDriver : public TrinamicBase {
|
class TrinamicUartDriver : public TrinamicBase {
|
||||||
private:
|
private:
|
||||||
|
Uart* _uart = nullptr;
|
||||||
|
|
||||||
static bool _uart_started;
|
static bool _uart_started;
|
||||||
|
|
||||||
TMC2209Stepper* tmcstepper; // all other driver types are subclasses of this one
|
TMC2209Stepper* tmcstepper; // all other driver types are subclasses of this one
|
||||||
|
Reference in New Issue
Block a user