double float = fal_float size added to lcec. LCNC starts and works

This commit is contained in:
Hakan Bastedt
2024-01-02 18:46:26 +01:00
parent 8007a2ff6c
commit b57bd740ab
7 changed files with 128 additions and 124 deletions

View File

@@ -1,56 +1,6 @@
<masters>
<master idx="0" appTimePeriod="1000000" refClockSyncCycles="5">
<slave idx="0" type="EK1100"/>
<slave idx="1" type="EL1008"/>
<slave idx="2" type="EL2008"/>
<slave idx="3" type="EL5101"/>
<slave idx="4" type="generic" vid="00000a88" pid="0a880002" configPdos="true">
<dcConf assignActivate="300" sync0Cycle="*1" sync0Shift="0"/>
<sdoConfig idx="2000" subIdx="0"><sdoDataRaw data ="b8 0b"/></sdoConfig> <!-- Max motor current (3.0A) -->
<sdoConfig idx="2003" subIdx="0"><sdoDataRaw data ="64 00"/></sdoConfig> <!-- Standby current percentage (100%) -->
<sdoConfig idx="2011" subIdx="0"><sdoDataRaw data ="00 00"/></sdoConfig> <!-- Open loop -->
<syncManager idx="2" dir="out">
<pdo idx="1600">
<pdoEntry idx="6040" subIdx="00" bitLen="16" halPin="cia-controlword" halType="u32"/>
<pdoEntry idx="6060" subIdx="00" bitLen="8" halPin="opmode" halType="s32"/>
<pdoEntry idx="607A" subIdx="00" bitLen="32" halPin="target-position" halType="s32"/>
<pdoEntry idx="60FF" subIdx="00" bitLen="32" halPin="target-velocity" halType="s32"/>
</pdo>
</syncManager>
<syncManager idx="3" dir="in">
<pdo idx="1a00">
<pdoEntry idx="6041" subIdx="00" bitLen="16" halPin="cia-statusword" halType="u32"/>
<pdoEntry idx="6061" subIdx="00" bitLen="8" halPin="opmode-display" halType="s32"/>
<pdoEntry idx="6064" subIdx="00" bitLen="32" halPin="actual-position" halType="s32"/>
<pdoEntry idx="606C" subIdx="00" bitLen="32" halPin="actual-velocity" halType="s32"/>
<pdoEntry idx="6077" subIdx="00" bitLen="32" halPin="actual-torque" halType="s32"/>
</pdo>
</syncManager>
</slave>
<slave idx="5" type="generic" vid="00000a88" pid="0a880002" configPdos="true">
<dcConf assignActivate="300" sync0Cycle="*1" sync0Shift="0"/>
<sdoConfig idx="2000" subIdx="0"><sdoDataRaw data ="68 10"/></sdoConfig> <!-- Max motor current (4.2A) -->
<sdoConfig idx="2003" subIdx="0"><sdoDataRaw data ="64 00"/></sdoConfig> <!-- Standby current percentage (100%) -->
<sdoConfig idx="2011" subIdx="0"><sdoDataRaw data ="00 00"/></sdoConfig> <!-- Open loop -->
<syncManager idx="2" dir="out">
<pdo idx="1600">
<pdoEntry idx="6040" subIdx="00" bitLen="16" halPin="cia-controlword" halType="u32"/>
<pdoEntry idx="6060" subIdx="00" bitLen="8" halPin="opmode" halType="s32"/>
<pdoEntry idx="607A" subIdx="00" bitLen="32" halPin="target-position" halType="s32"/>
<pdoEntry idx="60FF" subIdx="00" bitLen="32" halPin="target-velocity" halType="s32"/>
</pdo>
</syncManager>
<syncManager idx="3" dir="in">
<pdo idx="1a00">
<pdoEntry idx="6041" subIdx="00" bitLen="16" halPin="cia-statusword" halType="u32"/>
<pdoEntry idx="6061" subIdx="00" bitLen="8" halPin="opmode-display" halType="s32"/>
<pdoEntry idx="6064" subIdx="00" bitLen="32" halPin="actual-position" halType="s32"/>
<pdoEntry idx="606C" subIdx="00" bitLen="32" halPin="actual-velocity" halType="s32"/>
<pdoEntry idx="6077" subIdx="00" bitLen="32" halPin="actual-torque" halType="s32"/>
</pdo>
</syncManager>
</slave>
<slave idx="6" type="generic" vid="00aaa" pid="000bbbccc" configPdos="true">
<slave idx="0" type="generic" vid="00aaa" pid="000bbbccc" configPdos="true">
<dcConf assignActivate="300" sync0Cycle="*1" sync0Shift="0"/>
<syncManager idx="2" dir="out">
<pdo idx="1600">
@@ -59,14 +9,17 @@
<pdo idx="1601">
<pdoEntry idx="7001" subIdx="00" bitLen="32" halPin="enc-index-latch-enable" halType="u32"/>
</pdo>
<pdo idx="1602">
<pdoEntry idx="7002" subIdx="01" bitLen="64" halPin="commanded-position" halType="float-double"/>
</pdo>
</syncManager>
<syncManager idx="3" dir="in">
<pdo idx="1a00">
<pdoEntry idx="6000" subIdx="00" bitLen="32" halPin="enc-position" halType="float-ieee"/>
<pdoEntry idx="6000" subIdx="00" bitLen="64" halPin="enc-position" halType="float-double"/>
</pdo>
<pdo idx="1a01">
<pdoEntry idx="6001" subIdx="00" bitLen="32" halPin="enc-frequency" halType="float-ieee"/>
</pdo>
<pdoEntry idx="6001" subIdx="00" bitLen="64" halPin="enc-frequency" halType="float-double"/>
</pdo>
<pdo idx="1a02">
<pdoEntry idx="6002" subIdx="00" bitLen="32" halPin="DiffT" halType="u32"/>
</pdo>
@@ -76,7 +29,10 @@
<pdo idx="1a04">
<pdoEntry idx="6004" subIdx="00" bitLen="32" halPin="index-status" halType="u32"/>
</pdo>
</syncManager>
<pdo idx="1a05">
<pdoEntry idx="6005" subIdx="01" bitLen="64" halPin="actual-position" halType="float-double"/>
</pdo>
</syncManager>
</slave>
</master>
</masters>

View File

@@ -1,52 +1,102 @@
diff --git a/src/lcec_conf.c b/src/lcec_conf.c
index b0e9ad1..607c6d7 100644
index b0e9ad1..6cc7f8a 100644
--- a/src/lcec_conf.c
+++ b/src/lcec_conf.c
@@ -1267,6 +1267,11 @@ static void parsePdoEntryAttrs(LCEC_CONF_XML_INST_T *inst, int next, const char
p->halType = HAL_FLOAT;
continue;
}
+ if (strcasecmp(val, "float-lreal") == 0) {
+ p->subType = lcecPdoEntTypeFloatLREAL;
+ if (strcasecmp(val, "float-double") == 0) {
+ p->subType = lcecPdoEntTypeFloatDouble;
+ p->halType = HAL_FLOAT;
+ continue;
+ }
fprintf(stderr, "%s: ERROR: Invalid pdoEntry halType %s\n", modname, val);
XML_StopParser(inst->parser, 0);
return;
@@ -1410,6 +1415,11 @@ static void parseComplexEntryAttrs(LCEC_CONF_XML_INST_T *inst, int next, const c
p->halType = HAL_FLOAT;
continue;
}
+ if (strcasecmp(val, "float-double") == 0) {
+ p->subType = lcecPdoEntTypeFloatDouble;
+ p->halType = HAL_FLOAT;
+ continue;
+ }
fprintf(stderr, "%s: ERROR: Invalid complexEntry halType %s\n", modname, val);
XML_StopParser(inst->parser, 0);
return;
diff --git a/src/lcec_conf.h b/src/lcec_conf.h
index 5d9943c..2620938 100644
index 5d9943c..261c965 100644
--- a/src/lcec_conf.h
+++ b/src/lcec_conf.h
@@ -56,7 +56,8 @@ typedef enum {
@@ -55,6 +55,7 @@ typedef enum {
lcecPdoEntTypeSimple,
lcecPdoEntTypeFloatSigned,
lcecPdoEntTypeFloatUnsigned,
+ lcecPdoEntTypeFloatDouble,
lcecPdoEntTypeComplex,
- lcecPdoEntTypeFloatIeee
+ lcecPdoEntTypeFloatIeee,
+ lcecPdoEntTypeFloatLREAL
lcecPdoEntTypeFloatIeee
} LCEC_PDOENT_TYPE_T;
typedef enum {
diff --git a/src/lcec_generic.c b/src/lcec_generic.c
index dfddf73..dde7164 100644
index dfddf73..2f58fde 100644
--- a/src/lcec_generic.c
+++ b/src/lcec_generic.c
@@ -78,7 +78,7 @@ int lcec_generic_init(int comp_id, struct lcec_slave *slave, ec_pdo_entry_reg_t
@@ -26,6 +26,7 @@ hal_s32_t lcec_generic_read_s32(uint8_t *pd, lcec_generic_pin_t *hal_data);
hal_u32_t lcec_generic_read_u32(uint8_t *pd, lcec_generic_pin_t *hal_data);
void lcec_generic_write_s32(uint8_t *pd, lcec_generic_pin_t *hal_data, hal_s32_t sval);
void lcec_generic_write_u32(uint8_t *pd, lcec_generic_pin_t *hal_data, hal_u32_t uval);
+void lcec_generic_write_f64(uint8_t *pd, lcec_generic_pin_t *hal_data, hal_float_t fval);
int lcec_generic_init(int comp_id, struct lcec_slave *slave, ec_pdo_entry_reg_t *pdo_entry_regs) {
lcec_master_t *master = slave->master;
@@ -78,7 +79,7 @@ int lcec_generic_init(int comp_id, struct lcec_slave *slave, ec_pdo_entry_reg_t
case HAL_FLOAT:
// check data size
- if (hal_data->bitLength > 32) {
+ if (!(hal_data->bitLength == 32 || hal_data->bitLength == 64)) {
+ if (hal_data->bitLength > 64) {
rtapi_print_msg(RTAPI_MSG_WARN, LCEC_MSG_PFX "unable to export pin %s.%s.%s.%s: invalid process data bitlen!\n", LCEC_MODULE_NAME, master->name, slave->name, hal_data->name);
continue;
}
@@ -133,6 +133,8 @@ void lcec_generic_read(struct lcec_slave *slave, long period) {
@@ -133,6 +134,8 @@ void lcec_generic_read(struct lcec_slave *slave, long period) {
fval = lcec_generic_read_u32(pd, hal_data);
} else if(hal_data->subType == lcecPdoEntTypeFloatIeee){
fval = EC_READ_REAL(&pd[hal_data->pdo_os]);
+ } else if(hal_data->subType == lcecPdoEntTypeFloatLREAL){
+ } else if(hal_data->subType == lcecPdoEntTypeFloatDouble){
+ fval = EC_READ_LREAL(&pd[hal_data->pdo_os]);
} else {
fval = lcec_generic_read_s32(pd, hal_data);
}
@@ -185,6 +188,8 @@ void lcec_generic_write(struct lcec_slave *slave, long period) {
if (hal_data->subType == lcecPdoEntTypeFloatUnsigned) {
lcec_generic_write_u32(pd, hal_data, (hal_u32_t) fval);
+ } else if (hal_data->subType == lcecPdoEntTypeFloatDouble) {
+ lcec_generic_write_f64(pd, hal_data, fval);
} else {
lcec_generic_write_s32(pd, hal_data, (hal_s32_t) fval);
}
@@ -300,3 +305,22 @@ void lcec_generic_write_u32(uint8_t *pd, lcec_generic_pin_t *hal_data, hal_u32_t
}
}
+void lcec_generic_write_f64(uint8_t *pd, lcec_generic_pin_t *hal_data, hal_float_t fval) {
+ int i, offset;
+
+ if (hal_data->pdo_bp == 0 && hal_data->bitOffset == 0) {
+ EC_WRITE_LREAL(&pd[hal_data->pdo_os], fval);
+ }
+ union {
+ double d;
+ uin64_t u;
+ } v;
+ v.d = fval;
+ offset = ((hal_data->pdo_os << 3) | (hal_data->pdo_bp & 0x07)) + hal_data->bitOffset;
+ for (i=0; i < hal_data->bitLength; i++, offset++) {
+ EC_WRITE_BIT(&pd[offset >> 3], offset & 0x07,v.u & 1);
+ v.u >>= 1;
+ }
+#endif
+}
+