Added a commandedVelocity variable for hal

This commit is contained in:
Hakan Bastedt
2024-01-06 20:53:34 +01:00
parent ccde6ef15e
commit 9dcc713fab
6 changed files with 66 additions and 13 deletions

View File

@@ -125,7 +125,7 @@
</DataType> </DataType>
<DataType> <DataType>
<Name>DT1602</Name> <Name>DT1602</Name>
<BitSize>80</BitSize> <BitSize>144</BitSize>
<SubItem> <SubItem>
<SubIdx>0</SubIdx> <SubIdx>0</SubIdx>
<Name>Max SubIndex</Name> <Name>Max SubIndex</Name>
@@ -146,6 +146,16 @@
<Access>ro</Access> <Access>ro</Access>
</Flags> </Flags>
</SubItem> </SubItem>
<SubItem>
<SubIdx>2</SubIdx>
<Name>CommandedVelocity</Name>
<Type>ULINT</Type>
<BitSize>64</BitSize>
<BitOffs>80</BitOffs>
<Flags>
<Access>ro</Access>
</Flags>
</SubItem>
</DataType> </DataType>
<DataType> <DataType>
<Name>DT1A00</Name> <Name>DT1A00</Name>
@@ -414,7 +424,7 @@
</DataType> </DataType>
<DataType> <DataType>
<Name>DT7002</Name> <Name>DT7002</Name>
<BitSize>80</BitSize> <BitSize>144</BitSize>
<SubItem> <SubItem>
<SubIdx>0</SubIdx> <SubIdx>0</SubIdx>
<Name>Max SubIndex</Name> <Name>Max SubIndex</Name>
@@ -436,6 +446,17 @@
<PdoMapping>R</PdoMapping> <PdoMapping>R</PdoMapping>
</Flags> </Flags>
</SubItem> </SubItem>
<SubItem>
<SubIdx>2</SubIdx>
<Name>CommandedVelocity</Name>
<Type>LREAL</Type>
<BitSize>64</BitSize>
<BitOffs>80</BitOffs>
<Flags>
<Access WriteRestrictions="PreOP">ro</Access>
<PdoMapping>R</PdoMapping>
</Flags>
</SubItem>
</DataType> </DataType>
<DataType> <DataType>
<Name>ULINT</Name> <Name>ULINT</Name>
@@ -612,12 +633,12 @@
<Index>#x1602</Index> <Index>#x1602</Index>
<Name>StepGenIn1</Name> <Name>StepGenIn1</Name>
<Type>DT1602</Type> <Type>DT1602</Type>
<BitSize>80</BitSize> <BitSize>144</BitSize>
<Info> <Info>
<SubItem> <SubItem>
<Name>Max SubIndex</Name> <Name>Max SubIndex</Name>
<Info> <Info>
<DefaultValue>1</DefaultValue> <DefaultValue>2</DefaultValue>
</Info> </Info>
</SubItem> </SubItem>
<SubItem> <SubItem>
@@ -626,6 +647,12 @@
<DefaultValue>#x70020140</DefaultValue> <DefaultValue>#x70020140</DefaultValue>
</Info> </Info>
</SubItem> </SubItem>
<SubItem>
<Name>CommandedVelocity</Name>
<Info>
<DefaultValue>#x70020240</DefaultValue>
</Info>
</SubItem>
</Info> </Info>
<Flags> <Flags>
<Access>ro</Access> <Access>ro</Access>
@@ -1016,12 +1043,12 @@
<Index>#x7002</Index> <Index>#x7002</Index>
<Name>StepGenIn1</Name> <Name>StepGenIn1</Name>
<Type>DT7002</Type> <Type>DT7002</Type>
<BitSize>80</BitSize> <BitSize>144</BitSize>
<Info> <Info>
<SubItem> <SubItem>
<Name>Max SubIndex</Name> <Name>Max SubIndex</Name>
<Info> <Info>
<DefaultValue>1</DefaultValue> <DefaultValue>2</DefaultValue>
</Info> </Info>
</SubItem> </SubItem>
<SubItem> <SubItem>
@@ -1030,6 +1057,12 @@
<DefaultValue>0</DefaultValue> <DefaultValue>0</DefaultValue>
</Info> </Info>
</SubItem> </SubItem>
<SubItem>
<Name>CommandedVelocity</Name>
<Info>
<DefaultValue>0</DefaultValue>
</Info>
</SubItem>
</Info> </Info>
<Flags> <Flags>
<Access>ro</Access> <Access>ro</Access>
@@ -1077,6 +1110,13 @@
<Name>CommandedPosition</Name> <Name>CommandedPosition</Name>
<DataType>LREAL</DataType> <DataType>LREAL</DataType>
</Entry> </Entry>
<Entry>
<Index>#x7002</Index>
<SubIndex>#x2</SubIndex>
<BitLen>64</BitLen>
<Name>CommandedVelocity</Name>
<DataType>LREAL</DataType>
</Entry>
</RxPdo> </RxPdo>
<TxPdo Fixed="true" Mandatory="true" Sm="3"> <TxPdo Fixed="true" Mandatory="true" Sm="3">
<Index>#x1A00</Index> <Index>#x1A00</Index>

View File

@@ -33,7 +33,7 @@
#define SM3_smc 0x20 #define SM3_smc 0x20
#define SM3_act 1 #define SM3_act 1
#define MAX_MAPPINGS_SM2 3 #define MAX_MAPPINGS_SM2 4
#define MAX_MAPPINGS_SM3 6 #define MAX_MAPPINGS_SM3 6
#define MAX_RXPDO_SIZE 512 #define MAX_RXPDO_SIZE 512

View File

@@ -163,6 +163,13 @@
"data": "&Obj.StepGenIn1.CommandedPosition", "data": "&Obj.StepGenIn1.CommandedPosition",
"value": "0", "value": "0",
"access": "RO" "access": "RO"
},
{
"name": "CommandedVelocity",
"dtype": "REAL64",
"value": "0",
"access": "RO",
"data": "&Obj.StepGenIn1.CommandedVelocity"
} }
], ],
"pdo_mappings": [ "pdo_mappings": [

View File

@@ -22,6 +22,7 @@ static const char acName1601_01[] = "IndexLatchEnable";
static const char acName1602[] = "StepGenIn1"; static const char acName1602[] = "StepGenIn1";
static const char acName1602_00[] = "Max SubIndex"; static const char acName1602_00[] = "Max SubIndex";
static const char acName1602_01[] = "CommandedPosition"; static const char acName1602_01[] = "CommandedPosition";
static const char acName1602_02[] = "CommandedVelocity";
static const char acName1A00[] = "EncPos"; static const char acName1A00[] = "EncPos";
static const char acName1A00_00[] = "Max SubIndex"; static const char acName1A00_00[] = "Max SubIndex";
static const char acName1A00_01[] = "EncPos"; static const char acName1A00_01[] = "EncPos";
@@ -72,6 +73,7 @@ static const char acName7001[] = "IndexLatchEnable";
static const char acName7002[] = "StepGenIn1"; static const char acName7002[] = "StepGenIn1";
static const char acName7002_00[] = "Max SubIndex"; static const char acName7002_00[] = "Max SubIndex";
static const char acName7002_01[] = "CommandedPosition"; static const char acName7002_01[] = "CommandedPosition";
static const char acName7002_02[] = "CommandedVelocity";
const _objd SDO1000[] = const _objd SDO1000[] =
{ {
@@ -109,8 +111,9 @@ const _objd SDO1601[] =
}; };
const _objd SDO1602[] = const _objd SDO1602[] =
{ {
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1602_00, 1, NULL}, {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName1602_00, 2, NULL},
{0x01, DTYPE_UNSIGNED64, 64, ATYPE_RO, acName1602_01, 0x70020140, NULL}, {0x01, DTYPE_UNSIGNED64, 64, ATYPE_RO, acName1602_01, 0x70020140, NULL},
{0x02, DTYPE_UNSIGNED64, 64, ATYPE_RO, acName1602_02, 0x70020240, NULL},
}; };
const _objd SDO1A00[] = const _objd SDO1A00[] =
{ {
@@ -202,8 +205,9 @@ const _objd SDO7001[] =
}; };
const _objd SDO7002[] = const _objd SDO7002[] =
{ {
{0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7002_00, 1, NULL}, {0x00, DTYPE_UNSIGNED8, 8, ATYPE_RO, acName7002_00, 2, NULL},
{0x01, DTYPE_REAL64, 64, ATYPE_RO, acName7002_01, 0, &Obj.StepGenIn1.CommandedPosition}, {0x01, DTYPE_REAL64, 64, ATYPE_RO, acName7002_01, 0, &Obj.StepGenIn1.CommandedPosition},
{0x02, DTYPE_REAL64, 64, ATYPE_RO, acName7002_02, 0, &Obj.StepGenIn1.CommandedVelocity},
}; };
const _objectlist SDOobjects[] = const _objectlist SDOobjects[] =
@@ -215,7 +219,7 @@ const _objectlist SDOobjects[] =
{0x1018, OTYPE_RECORD, 4, 0, acName1018, SDO1018}, {0x1018, OTYPE_RECORD, 4, 0, acName1018, SDO1018},
{0x1600, OTYPE_RECORD, 1, 0, acName1600, SDO1600}, {0x1600, OTYPE_RECORD, 1, 0, acName1600, SDO1600},
{0x1601, OTYPE_RECORD, 1, 0, acName1601, SDO1601}, {0x1601, OTYPE_RECORD, 1, 0, acName1601, SDO1601},
{0x1602, OTYPE_RECORD, 1, 0, acName1602, SDO1602}, {0x1602, OTYPE_RECORD, 2, 0, acName1602, SDO1602},
{0x1A00, OTYPE_RECORD, 1, 0, acName1A00, SDO1A00}, {0x1A00, OTYPE_RECORD, 1, 0, acName1A00, SDO1A00},
{0x1A01, OTYPE_RECORD, 1, 0, acName1A01, SDO1A01}, {0x1A01, OTYPE_RECORD, 1, 0, acName1A01, SDO1A01},
{0x1A02, OTYPE_RECORD, 1, 0, acName1A02, SDO1A02}, {0x1A02, OTYPE_RECORD, 1, 0, acName1A02, SDO1A02},
@@ -233,6 +237,6 @@ const _objectlist SDOobjects[] =
{0x6005, OTYPE_RECORD, 1, 0, acName6005, SDO6005}, {0x6005, OTYPE_RECORD, 1, 0, acName6005, SDO6005},
{0x7000, OTYPE_VAR, 0, 0, acName7000, SDO7000}, {0x7000, OTYPE_VAR, 0, 0, acName7000, SDO7000},
{0x7001, OTYPE_VAR, 0, 0, acName7001, SDO7001}, {0x7001, OTYPE_VAR, 0, 0, acName7001, SDO7001},
{0x7002, OTYPE_RECORD, 1, 0, acName7002, SDO7002}, {0x7002, OTYPE_RECORD, 2, 0, acName7002, SDO7002},
{0xffff, 0xff, 0xff, 0xff, NULL, NULL} {0xffff, 0xff, 0xff, 0xff, NULL, NULL}
}; };

View File

@@ -30,6 +30,7 @@ typedef struct
struct struct
{ {
double CommandedPosition; double CommandedPosition;
double CommandedVelocity;
} StepGenIn1; } StepGenIn1;
} _Objects; } _Objects;

View File

@@ -35,7 +35,7 @@ volatile uint8_t pleaseZeroTheCounter = 0;
HardwareTimer *MyTim; HardwareTimer *MyTim;
volatile uint32_t stepCount = 0, stepPulses = 0; volatile uint32_t stepCount = 0, stepPulses = 0;
volatile double_t actualPosition = 0; volatile double_t actualPosition = 0;
volatile double_t requestedPosition; volatile double_t requestedPosition, requestedVelocity;
uint32_t sync0CycleTime = 0; uint32_t sync0CycleTime = 0;
@@ -56,6 +56,7 @@ void cb_set_outputs(void) // Master outputs gets here, slave inputs, first opera
PosScaleRes = 1.0 / double(CurPosScale); PosScaleRes = 1.0 / double(CurPosScale);
} }
requestedPosition = Obj.StepGenIn1.CommandedPosition; requestedPosition = Obj.StepGenIn1.CommandedPosition;
requestedVelocity = Obj.StepGenIn1.CommandedVelocity;
} }
void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation void cb_get_inputs(void) // Set Master inputs, slave outputs, last operation
@@ -211,7 +212,7 @@ void sync0Handler(void)
void handleStepper(void) void handleStepper(void)
{ {
byte forwardDirection = 0; // 1 if going forward byte forwardDirection = 0; // 1 if going forward
int32_t pulsesToGo = 1000 * (requestedPosition - actualPosition); int32_t pulsesToGo = 100 * (requestedPosition - actualPosition);
if (pulsesToGo != 0) if (pulsesToGo != 0)
makePulses(900, pulsesToGo); // Make the pulses using hardware timer makePulses(900, pulsesToGo); // Make the pulses using hardware timer