Skip to content

Commit 13386d8

Browse files
committed
Added axis cpr command
1 parent 11f92cb commit 13386d8

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

Firmware/FFBoard/Inc/Axis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct GearRatio_t{
8383
enum class Axis_commands : uint32_t{
8484
power=0x00,degrees=0x01,esgain,zeroenc,invert,idlespring,axisdamper,enctype,drvtype,
8585
pos,maxspeed,maxtorquerate,fxratio,curtorque,curpos,curspd,curaccel,reductionScaler,
86-
filterSpeed, filterAccel, filterProfileId
86+
filterSpeed, filterAccel, filterProfileId,cpr
8787
};
8888

8989
class Axis : public PersistentStorage, public CommandHandler, public ErrorHandler

Firmware/FFBoard/Inc/constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* For more settings see target_constants.h in a target specific folder
99
*/
1010

11-
static const uint8_t SW_VERSION_INT[3] = {1,9,3}; // Version as array. 8 bit each!
11+
static const uint8_t SW_VERSION_INT[3] = {1,9,4}; // Version as array. 8 bit each!
1212
#define MAX_AXIS 2 // ONLY USE 2 for now else screws HID Reports
1313

1414
//#define DEBUGLOG // Uncomment to enable some debug printouts

Firmware/FFBoard/Src/Axis.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ void Axis::registerCommands(){
8989
//Can only read exact filter settings
9090
registerCommand("filterSpeed", Axis_commands::filterSpeed, "Biquad filter freq and q*100 for speed", CMDFLAG_GET);
9191
registerCommand("filterAccel", Axis_commands::filterAccel, "Biquad filter freq and q*100 for accel", CMDFLAG_GET);
92+
93+
registerCommand("cpr", Axis_commands::cpr, "Reported encoder CPR",CMDFLAG_GET);
9294
}
9395

9496
/*
@@ -719,7 +721,7 @@ CommandStatus Axis::command(const ParsedCommand& cmd,std::vector<CommandReply>&
719721
break;
720722

721723
case Axis_commands::pos:
722-
if (cmd.type == CMDtype::get)
724+
if (cmd.type == CMDtype::get && this->drv->getEncoder() != nullptr)
723725
{
724726
replies.emplace_back(this->drv->getEncoder()->getPos());
725727
}
@@ -799,6 +801,21 @@ CommandStatus Axis::command(const ParsedCommand& cmd,std::vector<CommandReply>&
799801
}
800802
break;
801803

804+
case Axis_commands::cpr:
805+
if (cmd.type == CMDtype::get && this->drv->getEncoder() != nullptr)
806+
{
807+
uint32_t cpr = this->drv->getEncoder()->getCpr();
808+
TMC4671 *tmcdrv = dynamic_cast<TMC4671 *>(this->drv.get()); // Special case for TMC. Get the actual encoder resolution
809+
if (tmcdrv)
810+
{
811+
cpr = tmcdrv->getEncCpr();
812+
}
813+
replies.emplace_back(cpr);
814+
}else{
815+
return CommandStatus::ERR;
816+
}
817+
break;
818+
802819
default:
803820
return CommandStatus::NOT_FOUND;
804821
}

0 commit comments

Comments
 (0)