Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ActiveHoming #30

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 48 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# @simatic-ax.axftcmlib

![GitHub branch status](https://img.shields.io/github/checks-status/sjuergen/https%3A%2F%2Fgithub.jparrowsec.cn%2Fsimatic-ax%2Faxftcmlib/main)


## Description

This library was created for the `Fischertechnik Factorysimulation 24V`. It contains classes for the basic elements of this Model.
Expand Down Expand Up @@ -32,7 +35,7 @@ Simatic.Ax.axftcmlib

## Classes

## ControlModuleAbstract
### ControlModuleAbstract

This is a base class for all control modules

Expand Down Expand Up @@ -177,9 +180,51 @@ classDiagram

</details>

### Class Axis
## Axis

This Axis concept has the same look and feel like the Motion Control Library in Siamtic AX. It is designed for Fischertechnik Models whre just a simple On/Off-Motor is used.

### Class Diagram

```mermaid
classDiagram
class itfAxis {
+PowerOn()
+PowerOff()
}
class AxisBase {
<<abstract>>
+ Attach()
+ IsAttached()
+ TO_Axis
}
class SpeedAxis {
+MoveVelocity()
+TO_SpeedAxis
}
class PosAxis {
+MoveRelative()
+MoveAbsolute()
+TO_PosAxis
}

AxisBase <|-- SpeedAxis
SpeedAxis <|-- PosAxis
itfAxis <|-- AxisBase
TO_Axis <|-- TO_SpeedAxis
TO_SpeedAxis <|-- TO_PosAxis
AxisBase --> TO_Axis
SpeedAxis --> TO_SpeedAxis
PosAxis --> TO_PosAxis
SpeedAxis --|> itfSpeedAxis
PosAxis --|> itfPosAxis
```

### SpeedAxis

### PosAxis

The Axis consists of a motor and an Encoder
### MotorBiDirectional

<details><summary>Motor ... </summary>

Expand Down Expand Up @@ -247,50 +292,6 @@ If you haven't a hardware encoder for the Axis, then you can simulate this hardw

</details>

|Method|Description|
|-|-|
|RunCyclic()| Execute the cyclic evaluation of the axis|
|MoveVelocity(Velocity : LREAL, direction : Direction)| moves the axis with given speed into certain direction until Halt() is called|
|MoveRelative(velocity : LREAL, distance : LINT) : BOOL|moves the axis for a distance based on the current position|
|MoveAbsolute(velocity : LREAL, position : LINT) : BOOL|moves the axis based on a default point -> Axis needs to be homed|
|Homing(velocity : LREAL, direction : Direction) : BOOL|moves the axis into its homing position|
|Homing(Position : LINT) : BOOL| homes the axes without movement -> position is set to given value|
|Halt()|Stops all movement|
|GetPlcOpenState() : PlcOpenState | Returns current status of axis: Ready, busy, done, error|
|IsRUnning() : BOOL| Checks, if the axis is currently moving|

<details><summary>Example for the class Axis ... </summary>

```iec-st

VAR_GLOBAL
SortingLineMotor : BOOL; //Actual PLC-variable
MotorOutputWriterForward : BinOutput; //Used to write on the PLC-variable
MotorOutputWriterReverse : BinOutput; //Used to write on the PLC-variable
MotorClassInstance : MotorFT := (Forward := MotorOutputWriterForward, Reverse := MotorOutputWriterReverse ); //Class instance initialized with the needed OutputWriter

TimeProviderForAxis : TimeProvider; //Class instance
TimebasedEncoderForAxis : TimeBasedEncoder := (TimeProvider := TimeProviderForAxis, EncoderAxis := ConveyorbeltForSortingLine, Velocity := 1.0); //Class instance

AxisReferenceSwitch : BinSignal;
ConveyorbeltForSortingLine : Axis := (Motor := MotorForAxis, Encoder := TimebasedEncoderForAxis, ReferenceSwitch := AxisReferenceswitch);
END_VAR

PROGRAM
TimebasedEncoderForAxis.Evaluate(); //Checking the position every cycle -> must be called every cycle
TimeProviderForAxis.Evaluate(); //Checking the cycle time -> must be called every cycle

ConveyorbeltForSortingLine.RunCyclic(); //Must be called every cycle
ConveyorbeltForSortingLine.Homing(Position := 0);
ConveyorbeltForSortingLine.MoveAbsolute(Velocity := 1.0, Position := 4000);

MotorForwardOutputWriter.WriteCyclic(Q => SortingLineMotorForConveyor); // Write output signals
END_PROGRAM

```

</details>

## Markdownlint-cli

This workspace will be checked by the [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli) (there is also documented ho to install the tool) tool in the CI workflow automatically.
Expand Down
12 changes: 11 additions & 1 deletion src/Axis/PosAxis/PosAxis.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.Commands;

NAMESPACE Simatic.Ax.axftcmlib.Motion
Expand Down Expand Up @@ -25,6 +26,7 @@ NAMESPACE Simatic.Ax.axftcmlib.Motion
_commandMoveRelative : commandMoveRelative;
_commandMoveAbsolute : commandMoveAbsolute;
_commandHomeDirect : commandHomeDirect;
_commandActiveHoming : commandActiveHoming;
END_VAR

METHOD PROTECTED OVERRIDE MakeAxisAbstract
Expand Down Expand Up @@ -54,7 +56,15 @@ NAMESPACE Simatic.Ax.axftcmlib.Motion
Position : LREAL;
END_VAR
HomeDirect := _commandHomeDirect.Start(AxisRef := _PosAxisRef, Position := Position);

END_METHOD

METHOD PUBLIC ActiveHoming : itfCommand
VAR_INPUT
Position : LREAL;
Direction : Direction;
RefSensor : IBinSignal;
END_VAR
ActiveHoming := _commandActiveHoming.Start(AxisRef := _PosAxisRef, Direction := Direction, Position := Position, RefSensor := RefSensor);
END_METHOD
END_CLASS

Expand Down
75 changes: 75 additions & 0 deletions src/Axis/PosAxis/commandActiveHoming.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.IO.Input;
USING Simatic.Ax.Commands;
USING Simatic.Ax.IO.Input;

NAMESPACE Simatic.Ax.axftcmlib.Motion

CLASS INTERNAL commandActiveHoming
EXTENDS ExecuteCommand
VAR
_AxisRef : REF_TO TO_PosAxis;
_velocity : LREAL;
_direction : Direction;
_position : LREAL;
_iRefSensor : IBinSignal;
_exec : BOOL;
END_VAR

METHOD PUBLIC Start : itfCommand
VAR_INPUT
AxisRef : REF_TO TO_PosAxis;
Velocity : LREAL := 100.0;
Direction : Direction;
Position : LREAL := 0.0;
RefSensor : IBinSignal;
END_VAR
_AxisRef := AxisRef;
_velocity := Velocity;
_direction := Direction;
_position := Position;
_iRefSensor := RefSensor;
THIS.ExecuteWithRisingEdge();
Start := THIS;
END_METHOD

METHOD PROTECTED OVERRIDE Execute
IF NOT(_exec) THEN
RETURN;
END_IF;
IF (NOT _AxisRef^.isPowerdOn) THEN
THIS.SetError(WORD#16#8001);
ELSE
_AxisRef^.Run(TRUE);
IF (_iRefSensor.QRis()) THEN
_AxisRef^.Run(FALSE);
_Done := _AxisRef^.SetPosition(value := _position);
;
END_IF;
END_IF;
END_METHOD

METHOD PROTECTED OVERRIDE SetExecute
VAR_INPUT
exec : BOOL;
END_VAR
_exec := exec;
IF (exec) THEN
THIS.InitState();
IF (_AxisRef = NULL) THEN
THIS.SetError(WORD#16#8003);
RETURN;
ELSIF (_iRefSensor = NULL) THEN
THIS.SetError(WORD#16#8004);
RETURN;
END_IF;
IF (NOT _AxisRef^.isPowerdOn) THEN
THIS.SetError(WORD#16#8001);
ELSIF (_AxisRef^.IsRunning()) THEN
THIS.SetError(WORD#16#8002); // Can not be homed because axis is not stillstanding
END_IF;
END_IF;
END_METHOD
END_CLASS

END_NAMESPACE
19 changes: 4 additions & 15 deletions src/Motor/IMotor.st
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@

NAMESPACE Simatic.Ax.axftcmlib.Motion
// This interface provides methods to control a unidirectional motor.
INTERFACE IMotor
///Starts the Motor with a given direction and velocity
METHOD Move
VAR_INPUT
velocity : LREAL;
END_VAR
END_METHOD
///Stops every movement of the Motor
METHOD Halt
END_METHOD
END_INTERFACE

NAMESPACE Simatic.Ax.axftcmlib.Motion
// This interface provides methods to control a bidirectional motor.
INTERFACE IMotorBiDiretional EXTENDS IMotor
INTERFACE IMotorBiDiretional
///Starts the Motor with a given direction and velocity
METHOD Move
VAR_INPUT
Expand All @@ -23,5 +10,7 @@ NAMESPACE Simatic.Ax.axftcmlib.Motion
END_VAR
END_METHOD
///Stops every movement of the Motor
METHOD Halt
END_METHOD
END_INTERFACE
END_NAMESPACE
34 changes: 25 additions & 9 deletions src/Motor/MotorBiDirectional.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,49 @@ NAMESPACE Simatic.Ax.axftcmlib.Motion
///Class for creating a basic Motor
/// It supports two directions
/// It is used to power the axis
CLASS MotorFT EXTENDS MotorUniDirectional IMPLEMENTS IMotorBiDiretional
CLASS MotorFT
IMPLEMENTS IMotorBiDiretional
VAR PUBLIC
Forward : IBinOutput;
Reverse : IBinOutput;
END_VAR
VAR PROTECTED
END_VAR
///Starts the Motor with a given direction and velocity

METHOD PUBLIC Move
VAR_INPUT
velocity : LREAL;
direction : Direction;
END_VAR
IF (direction = Direction#PositiveDirection) THEN
Forward.SetOn();
Reverse.SetOff();
IF (Forward <> NULL) THEN
Forward.SetOn();
END_IF;
IF (Reverse <> NULL) THEN
Reverse.SetOff();
END_IF;
ELSE
Reverse.SetOn();
Forward.SetOff();
IF (Forward <> NULL) THEN
Forward.SetOff();
END_IF;
IF (Reverse <> NULL) THEN
Reverse.SetOn();
END_IF;
END_IF;
;
END_METHOD
///Stops every movement of the Motor
METHOD PUBLIC OVERRIDE Halt
Reverse.SetOff();
Forward.SetOff();

METHOD PUBLIC Halt
IF (Forward <> NULL) THEN
Forward.SetOff();
END_IF;
IF (Reverse <> NULL) THEN
Reverse.SetOff();
END_IF;
;
END_METHOD
END_CLASS

END_NAMESPACE
END_NAMESPACE
30 changes: 0 additions & 30 deletions src/Motor/MotorUniDirectional.st

This file was deleted.

Loading
Loading