From 63b7731d1e9e3ce7845587ae8164cb33e09c9433 Mon Sep 17 00:00:00 2001 From: Jim Morris Date: Fri, 29 Apr 2016 15:37:56 -0700 Subject: [PATCH] add designator to motordriver messages --- .../motordrivercontrol/MotorDriverControl.cpp | 25 ++++++++++--------- .../drivers/DRV8711/drv8711.cpp | 14 +++++------ .../drivers/DRV8711/drv8711.h | 4 +-- .../drivers/TMC26X/TMC26X.cpp | 16 ++++++------ .../drivers/TMC26X/TMC26X.h | 4 ++- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/modules/utils/motordrivercontrol/MotorDriverControl.cpp b/src/modules/utils/motordrivercontrol/MotorDriverControl.cpp index c1d333061a..b9d4efe712 100644 --- a/src/modules/utils/motordrivercontrol/MotorDriverControl.cpp +++ b/src/modules/utils/motordrivercontrol/MotorDriverControl.cpp @@ -70,13 +70,6 @@ void MotorDriverControl::on_module_loaded() bool MotorDriverControl::config_module(uint16_t cs) { - spi_cs_pin.from_string(THEKERNEL->config->value( motor_driver_control_checksum, cs, spi_cs_pin_checksum)->by_default("nc")->as_string())->as_output(); - if(!spi_cs_pin.connected()) { - THEKERNEL->streams->printf("MotorDriverControl ERROR: chip select not defined\n"); - return false; // if not defined then we can't use this instance - } - spi_cs_pin.set(1); - std::string str= THEKERNEL->config->value( motor_driver_control_checksum, cs, designator_checksum)->by_default("")->as_string(); if(str.empty()) { THEKERNEL->streams->printf("MotorDriverControl ERROR: designator not defined\n"); @@ -84,9 +77,17 @@ bool MotorDriverControl::config_module(uint16_t cs) } designator= str[0]; + spi_cs_pin.from_string(THEKERNEL->config->value( motor_driver_control_checksum, cs, spi_cs_pin_checksum)->by_default("nc")->as_string())->as_output(); + if(!spi_cs_pin.connected()) { + THEKERNEL->streams->printf("MotorDriverControl %c ERROR: chip select not defined\n", designator); + return false; // if not defined then we can't use this instance + } + spi_cs_pin.set(1); + + str= THEKERNEL->config->value( motor_driver_control_checksum, cs, chip_checksum)->by_default("")->as_string(); if(str.empty()) { - THEKERNEL->streams->printf("MotorDriverControl ERROR: chip type not defined\n"); + THEKERNEL->streams->printf("MotorDriverControl %c ERROR: chip type not defined\n", designator); return false; // chip type required } @@ -96,14 +97,14 @@ bool MotorDriverControl::config_module(uint16_t cs) if(str == "DRV8711") { chip= DRV8711; - drv8711= new DRV8711DRV(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3)); + drv8711= new DRV8711DRV(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3), designator); }else if(str == "TMC2660") { chip= TMC2660; - tmc26x= new TMC26X(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3)); + tmc26x= new TMC26X(std::bind( &MotorDriverControl::sendSPI, this, _1, _2, _3), designator); }else{ - THEKERNEL->streams->printf("MotorDriverControl ERROR: Unknown chip type: %s\n", str.c_str()); + THEKERNEL->streams->printf("MotorDriverControl %c ERROR: Unknown chip type: %s\n", designator, str.c_str()); return false; } @@ -118,7 +119,7 @@ bool MotorDriverControl::config_module(uint16_t cs) } else if(spi_channel == 1) { mosi = P0_9; miso = P0_8; sclk = P0_7; } else { - THEKERNEL->streams->printf("MotorDriverControl ERROR: Unknown SPI Channel: %d\n", spi_channel); + THEKERNEL->streams->printf("MotorDriverControl %c ERROR: Unknown SPI Channel: %d\n", designator, spi_channel); return false; } diff --git a/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.cpp b/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.cpp index db462d08b6..0c048f26b8 100644 --- a/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.cpp +++ b/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.cpp @@ -15,7 +15,7 @@ #define REGWRITE 0x00 #define REGREAD 0x80 -DRV8711DRV::DRV8711DRV(std::function spi) : spi(spi) +DRV8711DRV::DRV8711DRV(std::function spi, char d) : spi(spi), designator(d) { error_reported.reset(); } @@ -216,7 +216,7 @@ void DRV8711DRV::dump_status(StreamOutput *stream) DRIVE_Register_t R_DRIVE_REG; STATUS_Register_t R_STATUS_REG; - stream->printf("Register Dump:\n"); + stream->printf("designator: %c, Register Dump:\n", designator); // Read CTRL Register R_CTRL_REG.raw= ReadRegister(G_CTRL_REG.Address); @@ -332,7 +332,7 @@ bool DRV8711DRV::check_alarm() R_STATUS_REG.raw= ReadRegister(G_STATUS_REG.Address); if(R_STATUS_REG.OTS) { - if(!error_reported.test(0)) THEKERNEL->streams->printf("ERROR: Overtemperature shutdown\n"); + if(!error_reported.test(0)) THEKERNEL->streams->printf("%c, ERROR: Overtemperature shutdown\n", designator); error= true; error_reported.set(0); }else{ @@ -341,7 +341,7 @@ bool DRV8711DRV::check_alarm() if(R_STATUS_REG.AOCP) { - if(!error_reported.test(1)) THEKERNEL->streams->printf("ERROR: Channel A over current shutdown\n"); + if(!error_reported.test(1)) THEKERNEL->streams->printf("%c, ERROR: Channel A over current shutdown\n", designator); error= true; error_reported.set(1); }else{ @@ -350,7 +350,7 @@ bool DRV8711DRV::check_alarm() if(R_STATUS_REG.BOCP) { - if(!error_reported.test(2)) THEKERNEL->streams->printf("ERROR: Channel B over current shutdown\n"); + if(!error_reported.test(2)) THEKERNEL->streams->printf("%c, ERROR: Channel B over current shutdown\n", designator); error= true; error_reported.set(2); }else{ @@ -358,7 +358,7 @@ bool DRV8711DRV::check_alarm() } if(R_STATUS_REG.APDF) { - if(!error_reported.test(3)) THEKERNEL->streams->printf("ERROR: Channel A predriver fault\n"); + if(!error_reported.test(3)) THEKERNEL->streams->printf("%c, ERROR: Channel A predriver fault\n", designator); error= true; error_reported.set(3); }else{ @@ -367,7 +367,7 @@ bool DRV8711DRV::check_alarm() if(R_STATUS_REG.BPDF) { - if(!error_reported.test(4)) THEKERNEL->streams->printf("ERROR: Channel B predriver fault\n"); + if(!error_reported.test(4)) THEKERNEL->streams->printf("%c, ERROR: Channel B predriver fault\n", designator); error= true; error_reported.set(4); }else{ diff --git a/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.h b/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.h index 14b049bcc9..a4bfec25d9 100644 --- a/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.h +++ b/src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.h @@ -8,7 +8,7 @@ class StreamOutput; class DRV8711DRV { public: - DRV8711DRV(std::function spi); + DRV8711DRV(std::function spi, char designator); void init(uint16_t cs) ; @@ -142,7 +142,7 @@ class DRV8711DRV float resistor{0.05}; std::bitset<8> error_reported; uint8_t gain{20}; - + char designator; // float _amps; // uint8_t _microstepreg; diff --git a/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.cpp b/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.cpp index b719c7028b..7ee2754256 100644 --- a/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.cpp +++ b/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.cpp @@ -157,7 +157,7 @@ /* * Constructor */ -TMC26X::TMC26X(std::function spi) : spi(spi) +TMC26X::TMC26X(std::function spi, char d) : spi(spi), designator(d) { //we are not started yet started = false; @@ -863,7 +863,7 @@ bool TMC26X::isCurrentScalingHalfed() void TMC26X::dumpStatus(StreamOutput *stream, bool readable) { if (readable) { - stream->printf("Chip type TMC26X\n"); + stream->printf("designator %c, Chip type TMC26X\n", designator); check_error_status_bits(stream); @@ -966,14 +966,14 @@ bool TMC26X::check_error_status_bits(StreamOutput *stream) readStatus(TMC26X_READOUT_POSITION); // get the status bits if (this->getOverTemperature()&TMC26X_OVERTEMPERATURE_PREWARING) { - if(!error_reported.test(0)) stream->printf("WARNING: Overtemperature Prewarning!\n"); + if(!error_reported.test(0)) stream->printf("%c - WARNING: Overtemperature Prewarning!\n", designator); error_reported.set(0); }else{ error_reported.reset(0); } if (this->getOverTemperature()&TMC26X_OVERTEMPERATURE_SHUTDOWN) { - if(!error_reported.test(1)) stream->printf("ERROR: Overtemperature Shutdown!\n"); + if(!error_reported.test(1)) stream->printf("%c - ERROR: Overtemperature Shutdown!\n", designator); error=true; error_reported.set(1); }else{ @@ -981,7 +981,7 @@ bool TMC26X::check_error_status_bits(StreamOutput *stream) } if (this->isShortToGroundA()) { - if(!error_reported.test(2)) stream->printf("ERROR: SHORT to ground on channel A!\n"); + if(!error_reported.test(2)) stream->printf("%c - ERROR: SHORT to ground on channel A!\n", designator); error=true; error_reported.set(2); }else{ @@ -989,7 +989,7 @@ bool TMC26X::check_error_status_bits(StreamOutput *stream) } if (this->isShortToGroundB()) { - if(!error_reported.test(3)) stream->printf("ERROR: SHORT to ground on channel B!\n"); + if(!error_reported.test(3)) stream->printf("%c - ERROR: SHORT to ground on channel B!\n", designator); error=true; error_reported.set(3); }else{ @@ -998,7 +998,7 @@ bool TMC26X::check_error_status_bits(StreamOutput *stream) // these seem to be triggered when moving so ignore them for now if (this->isOpenLoadA()) { - if(!error_reported.test(4)) stream->printf("ERROR: Channel A seems to be unconnected!\n"); + if(!error_reported.test(4)) stream->printf("%c - ERROR: Channel A seems to be unconnected!\n", designator); error=true; error_reported.set(4); }else{ @@ -1006,7 +1006,7 @@ bool TMC26X::check_error_status_bits(StreamOutput *stream) } if (this->isOpenLoadB()) { - if(!error_reported.test(5)) stream->printf("ERROR: Channel B seems to be unconnected!\n"); + if(!error_reported.test(5)) stream->printf("%c - ERROR: Channel B seems to be unconnected!\n", designator); error=true; error_reported.set(5); }else{ diff --git a/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.h b/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.h index c0bf7440d7..6c1069730c 100644 --- a/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.h +++ b/src/modules/utils/motordrivercontrol/drivers/TMC26X/TMC26X.h @@ -57,7 +57,7 @@ class TMC26X * You can select a different stepping with setMicrosteps() to aa different value. * \sa start(), setMicrosteps() */ - TMC26X(std::function spi); + TMC26X(std::function spi, char designator); /*! * \brief configures the TMC26X stepper driver. Before you called this function the stepper driver is in nonfunctional mode. @@ -445,5 +445,7 @@ class TMC26X }; uint8_t cool_step_lower_threshold; // we need to remember the threshold to enable and disable the CoolStep feature + char designator; + };