Skip to content

Commit

Permalink
ported(44895a7): add single DoF specialization for AtTime
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbesler committed Nov 24, 2023
1 parent 17248bc commit 517a97f
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .Zeugwerk/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Struckig",
"plcs": [
{
"version": "0.9.0.0",
"version": "0.9.3.0",
"name": "Struckig",
"type": "Library",
"frameworks": {},
Expand Down
2 changes: 1 addition & 1 deletion Struckig/Struckig/Struckig/Struckig.plcproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<LibraryReferences>{f4bffdbd-5758-46b1-8be5-022517971003}</LibraryReferences>
<Released>false</Released>
<Title>Struckig</Title>
<ProjectVersion>0.9.0.0</ProjectVersion>
<ProjectVersion>0.9.3.0</ProjectVersion>
<DefaultNamespace>Struckig</DefaultNamespace>
<Author>Stefan Besler and contributers</Author>
<Company>Stefan Besler</Company>
Expand Down
11 changes: 11 additions & 0 deletions Struckig/Struckig/Struckig/Struckig/IOtg.TcIO
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ VAR_INPUT
new_velocity : POINTER TO LREAL;
new_acceleration : POINTER TO LREAL;
new_section : POINTER TO INT;
END_VAR]]></Declaration>
</Method>
<Method Name="AtTime1" Id="{0d37baef-f79a-4d1b-9576-a2376af604c9}">
<Declaration><![CDATA[/// \copydoc Struckig.Otg#AtTime1
{attribute 'conditionalshow'}
METHOD AtTime1
VAR_INPUT
t : LREAL;
new_position : REFERENCE TO LREAL;
new_velocity : REFERENCE TO LREAL;
new_acceleration : REFERENCE TO LREAL;
END_VAR]]></Declaration>
</Method>
<Method Name="Cyclic" Id="{d26b89d9-5de1-4e69-9c66-3af979a1e1cd}">
Expand Down
24 changes: 22 additions & 2 deletions Struckig/Struckig/Struckig/Struckig/Otg.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ _errorId := errorId;]]></ST>
</Implementation>
</Method>
<Method Name="AtTime" Id="{bf1093a4-cb3c-415c-bc2d-e44ec3ea9553}">
<Declaration><![CDATA[{attribute 'conditionalshow'}
<Declaration><![CDATA[/// Get the kinematic state at a given time
{attribute 'conditionalshow'}
METHOD AtTime
VAR_INPUT
t : LREAL;
Expand All @@ -152,7 +153,7 @@ END_VAR]]></Declaration>
RETURN;
END_IF
new_section := 0;
//new_section := 0;
FOR dof:=0 TO _dofsEnd DO
p REF= _profiles[dof];
Expand Down Expand Up @@ -208,6 +209,25 @@ FOR dof:=0 TO _dofsEnd DO
END_FOR]]></ST>
</Implementation>
</Method>
<Method Name="AtTime1" Id="{d543d75f-6e83-4f40-aeff-b8c350fca5a8}">
<Declaration><![CDATA[/// Get the kinematic state and current section at a given time without vectors for a single DoF.
/// Using this method is only allowed for DoF = 1, for higher degrees of freedom use
/// [AtTime](xref:Struckig.Otg#AtTime). Using this method for DoF > 0 will not yield any result
{attribute 'conditionalshow'}
METHOD AtTime1
VAR_INPUT
t : LREAL;
new_position : REFERENCE TO LREAL;
new_velocity : REFERENCE TO LREAL;
new_acceleration : REFERENCE TO LREAL;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[IF _dofs = 1
THEN
AtTime(t, ADR(new_position), ADR(new_velocity), ADR(new_acceleration), 0);
END_IF]]></ST>
</Implementation>
</Method>
<Method Name="Calculate" Id="{d4e77b2d-b7a2-4486-8e6b-9e101a6d8b8b}">
<Declaration><![CDATA[METHOD PRIVATE Calculate : TrajectoryErrorCode
VAR_INST
Expand Down
14 changes: 14 additions & 0 deletions Struckig/Struckig/Struckig/Struckig/Otg1.TcPOU
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ END_VAR]]></Declaration>
<ST><![CDATA[_otg.AtTime(t, new_position, new_velocity, new_acceleration, new_section);]]></ST>
</Implementation>
</Method>
<Method Name="AtTime1" Id="{1d694463-453a-4697-a59a-2e7b7e0e0ffd}">
<Declaration><![CDATA[/// \copydoc Struckig.Otg#AtTime1
{attribute 'conditionalshow'}
METHOD AtTime1
VAR_INPUT
t : LREAL;
new_position : REFERENCE TO LREAL;
new_velocity : REFERENCE TO LREAL;
new_acceleration : REFERENCE TO LREAL;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[_otg.AtTime1(t, new_position, new_velocity, new_acceleration);]]></ST>
</Implementation>
</Method>
<Method Name="Cyclic" Id="{222cfd84-0828-4551-b3bf-cdb6fa696da0}">
<Declaration><![CDATA[/// \copydoc Struckig.Otg#Cyclic
METHOD Cyclic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ TYPE SynchronizationType :
Undefined,
TimeSync, //< Always synchronize the DoFs to reach the target at the same time (Default)
TimeIfNecessarySync, //< Synchronize only when necessary (e.g. for non-zero target velocity or acceleration)
Phase, ///< Phase synchronize the DoFs when this is possible, else fallback to "Time" strategy. Phase synchronization will result a straight-line trajectory
// PhaseOnly, ///< Always phase synchronize the DoFs (even when this is not time-optimal), else returns "ErrorNoPhaseSynchronization". Ruckig will then guarantee a straight-line trajectory
None //! Calculate every DoF independently
Phase, //< Phase synchronize the DoFs when this is possible, else fallback to "Time" strategy. Phase synchronization will result a straight-line trajectory
// PhaseOnly, //< Always phase synchronize the DoFs (even when this is not time-optimal), else returns "ErrorNoPhaseSynchronization". Ruckig will then guarantee a straight-line trajectory
None //< Calculate every DoF independently
);
END_TYPE
]]></Declaration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<Declaration><![CDATA[{attribute 'qualified_only'}
TYPE TrajectoryErrorCode :
(
Undefined := 0,
InvalidInput,
Undefined := 0,
InvalidInput, //< Error in the input parameter
SynchronizationFailed,
CalculateStep1Failed
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
TYPE TrajectoryState :
(
Undefined,
/// The trajectory has reached its final position. For trajectories with a target velocity or/and a target acceleration
/// there will still be movement.
Idle,
/// The trajectory is calculated normally
Busy,
/// An error occured, use [ErrorCode](Struckig.IOtg#ErrorCode) and [ErrorMessage](Struckig.IOtg#ErrorMessage) to get more
/// information about the error.
Error
);
END_TYPE
Expand Down
4 changes: 2 additions & 2 deletions tests/.Zeugwerk/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"name": "Struckig_unittest",
"plcs": [
{
"version": "0.9.0.0",
"version": "0.9.3.0",
"name": "Struckig_unittest",
"type": "Application",
"frameworks": {},
"references": {
"*": [
"Struckig=0.9.0.0",
"Struckig=0.9.3.0",
"Tc3_Module=*",
"TcUnit=*"
]
Expand Down
2 changes: 1 addition & 1 deletion tests/Struckig_unittest/Struckig_unittest.tsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</System>
<Plc>
<Project GUID="{D01D1C3D-8E1A-4350-AEDC-05EAE2EFCF27}" Name="Struckig_unittest" PrjFilePath="Struckig_unittest\Struckig_unittest.plcproj" TmcFilePath="Struckig_unittest\Struckig_unittest.tmc" ReloadTmc="true" AmsPort="851" FileArchiveSettings="#x000e" SymbolicMapping="true">
<Instance Id="#x08502000" TcSmClass="TComPlcObjDef" KeepUnrestoredLinks="2" TmcPath="Struckig_unittest\Struckig_unittest.tmc" TmcHash="{EC611819-5991-4CE9-8566-F45A78C162EB}">
<Instance Id="#x08502000" TcSmClass="TComPlcObjDef" KeepUnrestoredLinks="2" TmcPath="Struckig_unittest\Struckig_unittest.tmc" TmcHash="{EB14F6DF-3C7D-C5BE-93FF-15D34BBE132A}">
<Name>Struckig_unittest Instance</Name>
<CLSID ClassFactory="TcPlc30">{08500001-0000-0000-F000-000000000064}</CLSID>
<Contexts>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ VAR
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[Test_AtTime();
Test_AtTime1();
Test_AtTime1_2();
Test_DurationDiscretization();
Test_EnabledDof();
Test_FirstStateAtTime();
Test_IndependentMinDurations();
Test_InvalidInput();
Test_IndependentMinDurations_1();
Test_InputInitalized();
Test_InputValidation();
Test_InvalidInput();
Test_PerDofSettings();
Test_PerDofSettings_1();
Test_PhaseSynchronization();
Test_PositionExtrema();
Test_DurationDiscretization();
Test_InputInitalized();
Test_IndependentMinDurations_1();]]></ST>
]]></ST>
</Implementation>
<Method Name="Test_AtTime" Id="{8747a524-a952-4b4b-9b1d-d5709bbaaf50}">
<Declaration><![CDATA[METHOD Test_AtTime
Expand Down Expand Up @@ -75,6 +80,93 @@ values[1] := -2.6871268303;
values[2] := 1.0;
AssertArrayEquals_LREAL(values, NewPosition, 1E-9, message:='');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_AtTime1" Id="{6b9a2765-c384-4cf1-ad5e-1b9d190a840a}">
<Declaration><![CDATA[METHOD Test_AtTime1
VAR_INST
otg : Struckig.Otg(0.005, 1) := (
CurrentPosition := [ 0.0 ],
CurrentVelocity := [ 0.0 ],
CurrentAcceleration := [ 0.0 ],
TargetPosition := [ 1.0 ],
TargetVelocity := [ 0.0 ],
TargetAcceleration := [ 0.0 ],
MaxVelocity := [ 1.0 ],
MaxAcceleration := [ 1.0 ],
MaxJerk := [ 1.0 ],
EnableAutoPropagate := FALSE
);
END_VAR
VAR
result : Struckig.TrajectoryState;
newPosition, newVelocity, newAcceleration : LREAL;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('AtTime1');
otg();
AssertEquals_INT(Expected := Struckig.TrajectoryState.Busy, Actual := otg.State, Message := '');
AssertEquals_LREAL(3.1748, otg.Duration, 1E-4, Message:='');
otg.AtTime1(0, newPosition, newVelocity, newAcceleration);
AssertEquals_LREAL(otg.CurrentPosition[0], newPosition, 1E-5, Message:='');
otg.AtTime1(3.1748 / 2, newPosition, newVelocity, newAcceleration);
AssertEquals_LREAL(0.5, newPosition, 1E-4, Message:='');
otg.AtTime1(3.1748, newPosition, newVelocity, newAcceleration);
AssertEquals_LREAL(1.0, newPosition, 1E-4, Message:='');
AssertEquals_LREAL(0.0, newVelocity, 1E-4, Message:='');
AssertEquals_LREAL(0.0, newAcceleration, 1E-4, Message:='');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
<Method Name="Test_AtTime1_2" Id="{96218005-af63-4d3f-bab2-ab982daff044}">
<Declaration><![CDATA[METHOD Test_AtTime1_2
VAR_INST
otg : Struckig.Otg(0.005, 2) := (
CurrentPosition := [ 0.0, 0.0 ],
CurrentVelocity := [ 0.0, 0.0 ],
CurrentAcceleration := [ 0.0, 0.0 ],
TargetPosition := [ 1.0, 1.0 ],
TargetVelocity := [ 0.0, 0.0 ],
TargetAcceleration := [ 0.0, 0.0 ],
MaxVelocity := [ 1.0, 1.0 ],
MaxAcceleration := [ 1.0, 1.0 ],
MaxJerk := [ 1.0, 1.0 ],
EnableAutoPropagate := FALSE
);
END_VAR
VAR
result : Struckig.TrajectoryState;
newPosition, newVelocity, newAcceleration : LREAL;
END_VAR]]></Declaration>
<Implementation>
<ST><![CDATA[TEST('AtTime1_2');
otg();
AssertEquals_INT(Expected := Struckig.TrajectoryState.Busy, Actual := otg.State, Message := '');
AssertEquals_LREAL(3.1748, otg.Duration, 1E-4, Message:='');
newPosition := 5;
otg.AtTime1(0, newPosition, newVelocity, newAcceleration);
AssertEquals_LREAL(5.0, newPosition, 1E-4, Message:='No calculation with AtTime1 if DoF != 1');
otg.AtTime1(3.1748 / 2, newPosition, newVelocity, newAcceleration);
AssertEquals_LREAL(5.0, newPosition, 1E-4, Message:='No calculation with AtTime1 if DoF != 1');
otg.AtTime1(3.1748, newPosition, newVelocity, newAcceleration);
AssertEquals_LREAL(5.0, newPosition, 1E-4, Message:='No calculation with AtTime1 if DoF != 1');
TEST_FINISHED();]]></ST>
</Implementation>
</Method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<Implicit_KindOfTask>{23a670f4-2417-4917-907e-f416baaaec8d}</Implicit_KindOfTask>
<Implicit_Jitter_Distribution>{58f48993-e77e-4536-bff7-b0d34be7acb8}</Implicit_Jitter_Distribution>
<LibraryReferences>{604fede9-7b95-4a71-aceb-a9436682d543}</LibraryReferences>
<ProjectVersion>0.9.0.0</ProjectVersion>
<ProjectVersion>0.9.3.0</ProjectVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="PlcTask.TcTTO">
Expand Down Expand Up @@ -102,7 +102,7 @@
</ItemGroup>
<ItemGroup>
<PlaceholderReference Include="Struckig">
<DefaultResolution>Struckig, 0.9.0.0 (Stefan Besler)</DefaultResolution>
<DefaultResolution>Struckig, 0.9.3.0 (Stefan Besler)</DefaultResolution>
<Namespace>Struckig</Namespace>
</PlaceholderReference>
<PlaceholderReference Include="Tc3_Module">
Expand Down Expand Up @@ -130,7 +130,7 @@
</ItemGroup>
<ItemGroup>
<PlaceholderResolution Include="Struckig">
<Resolution>Struckig, 0.9.0.0 (Stefan Besler)</Resolution>
<Resolution>Struckig, 0.9.3.0 (Stefan Besler)</Resolution>
</PlaceholderResolution>
<PlaceholderResolution Include="Tc3_Module">
<Resolution>Tc3_Module, * (Beckhoff Automation GmbH)</Resolution>
Expand Down

0 comments on commit 517a97f

Please sign in to comment.