Giter Club home page Giter Club logo

opensml's Introduction

OpenSML

Open Sources SoftMotion Light For CiA402 Servo Drivers

Tips:
Library file should worked on CODESYS and TwinCAT3, Quadratic velocity ramp calc we used Struckig Library.

There is suggest to read keba servoone usermanual to get more information about cia402.
Also i suggest that use Absolute Encoder, You don't need do reference travel at every start.
And if you have any questions please feel free to push your issues.

Why

Codesys is the best PLC programming platform. With the Raspberry Pi, you can get an advanced plc programming environment at a very low price. However, the softmotion license was canceled in the latest version of codesys for raspberry pi. (> 3.5.14.40, which means Raspberry Pi 4 must pay to get a softmotion license)

The motion control used by most customers is very simple and does not involve interpolation motion.

This project aims to provide the open source cia402 motion library for codesys or twincat users.

Target

In theory, an interpolation procedure can be made, similar to CNC. I am still working hard for this, but time is not guaranteed.

How

I only use ST (Struct text language) programming and add as many comments as possible.

Example for MC_Power:

Power_X(Axis:=Axis_X,xEnable:=Enable);

Example for Home And Absolute Position Move:

CASE iState OF
	0:
		Power_X(Axis:=Axis_X,xEnable:=xStart);
		IF Power_X.xDone THEN
			iState:=10;
		END_IF;
	10:
		Home_X(Axis:=Axis_X , xEnable:=xHomeEnable);
		IF Home_X.xDone THEN
			iState:=20;
		END_IF
	20:
		ProfilePosition_X(
			Axis:=Axis_X , 
			xEnable:=xMoveEnable , 
			xExecute:=xMoveExecute , 
			xContinueMove:=FALSE , 
			xRelativeMode:=FALSE , 
			diTargetPosition:=diTarget , 
			udiProfileVelocity:=udiVel);
END_CASE

Example for Cyclic Synchronous Position Mode:

Power_X(Axis:=Axis_X,xEnable:=Enable);
SyncPosition_X(
	Axis:=Axis_X , 
	MaxVelocity:=2000 , 
	MaxAcceleration:=20000 , 
	MaxJerk:=200000 , 
	CycleTime:=0.001 , 
	TargetPosition:=rTarget , 
	xEnable:=TRUE , 
	lrScale:=1.0 , 
	xSimulation:=TRUE,
	xError=> );

TODO

FuncBlock Status Name
Struct OpenSML_Axis
Power OpenSML_Power
Reset (use OpenSML_Power)
Home OpenSML_Home
Halt OpenSML_Stop
MoveAbsolute OpenSML_ProfilePosition
MoveVelocity OpenSML_ProfileVelocity
MoveRelative OpenSML_ProfilePosition
Stop OpenSML_Stop
Jog 🚧 -
TouchProbe 🚧 -
Cyclic Synchronous Velocity Mode OpenSML_SyncVelocity
Cyclic Synchronous Position Mode OpenSML_SyncPosition

Velocity Ramp

Quadratic velocity ramp calculate is very, very, very difficulty. Its simple when calc a curve, but its complexable when break a move without speed jitter.

I had create a 6th velocity ramp base g2 at #4 (comment) , But it cannot break a move. This is unacceptable for most applications.

Struckig and Ruckig is for multi dof robot calc, Ruckig calculates a trajectory to a target waypoint (with position, velocity, and acceleration) starting from any initial state limited by velocity, acceleration, and jerk constraints. It already finish mostily job in CSP moveabsolute. Also..it have a little bug, when i use Struckig, sometime it get non-zero acceleration when finished, it wll cause exception move. I had remove some funcition, reduce program size and make it work with OpenSML. For now its still in test, If you found some bug please push your issues. Thanks.

At this trace,

  1. POU.otg.CurrentPosition from struckig.
  2. POU.Axis1.fSetPosition from SM3_Basic.
  3. POU.csp.otg.CurrentPosition from OpenSML_SyncPosition.

They overlap perfectly, diff < 1e-8.

Overflow

PDO use DINT as TargetPosition, Range is -2147483648 ~ 2147483647. It could overflow. For Example:
A Servo Driver use 24bit encoder, its 16777216 pulse/rev(16#1000000). Normally Driver parameter will to be divided by 16(16#10), So its 1048576 pulse/rev(16#100000) for EtherCAT PDO(TargetPosition). If we use pitch=5mm ball screw, its 209715.2 pulse/mm.

So, if we dont want overflow, The position range is -10240 ~ 10239mm.
Overflow will automatic sum at some servo driver. so driver can accept overflow. But, if overflow happend, and OpenSML_SyncPosition FunctionBlock xEnable drop down, we cannot know how many overflow happend. When xEnable up, Actual position not equal OpenSML_SyncPosition feedback. It could make some exception move.

If you need a large move range, make sure not overflow. Also, Some servo driver cannot accept overflow.

opensml's People

Contributors

feecat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opensml's Issues

Help wanted

Hi,
I want to use this library but I have some problems settings thing up.
I get the following error:
'SM3_Drive_ETC_DS402_CyclicSync.AXIS_REF_ETC_DS402_CS' is not equal to type 'OpenSML_Axis' of VAR_IN_OUT 'Axis'
It would be of great help if somebody has a sample project for me, or can tell me what steps to take after importing this library.
Thanks in advance!!

About QuickStop and Jog

I have a question about quickstop,in FunctionBlock OpenSML_Power I see the following code

Axis.ControlWord.2:=xEmergencyStop;//QuickStop
This means that the flag bit is set to 1 when I want to execute QuickStop cmd.

But in some documents about CiA402 ,it seems that in Normal state(e.g. Operation Enable) this bit2 flag is 1.
And, instead, this flag bit is set to 0 when the QuickStop command is executed.
Is this due to different drive manufacturers?

In addition, I think it is possible to achieve the Jog function by speed mode(Operation mode = 3).

OpenSML_Axiscontroller axis not enabling

Hi,

This is the first time i use Github for bug report so forgive me if i am not doing it wrong.

I noticed a small bug in the latest OpenSML.library V1.9.

When using the OpenSML_Axiscontroller FB the first time after starting the controller.
At STEP 10 of the state machine the axis gets disabled because the mode of operation has to be set first
there is a line to enable the axis again after operating mode = 8 but because the axis was enabled first the Axis.StatusWord.2 is still true and the state machine steps to STEP 20 before the axis is enabled again.

see the code change i made to fix this:

10://Set Mode
	Axis.Modes_of_operation:=8;//Cyclic Synchronous Position Mode
	Axis.ControlWord.3:=Axis.Modes_of_operation_display=8;//Success change mode, enable operation
	otg.CurrentPosition:=DINT_TO_LREAL(Axis.Position_Actual_Value) / Control.Scale;//Write actual position to otg
	IF Axis.StatusWord.2 **AND (Axis.Modes_of_operation_display=8)** THEN//Operation Enabled
		iState:=20;
	END_IF

I made another change to be able to change the cycle time of the otg FB, it was fixed to 0.01...

	otg(
		ControlInterface:= InterfaceType,//ControlInterfaceType.Position , 
		TargetPosition:= Control.lrFollowPosition , 
		TargetVelocity:= JogVel , 
		TargetAcceleration:= 0 , 
		CycleTIme:= **Control.CycleTime**,//was 0.01
		MaxVelocity:= MoveVel,//Control.para.MaxVelocity , 
		MaxAcceleration:= Control.MaxAcceleration , 
		MaxJerk:= Control.MaxJerk);//accept new position and going on

BR,
Rinie

Great Work, some improvements

Congratulations on this project!
I have prepared the OpenSML_TC3.library file to be able to use your great work with Twincat.
I have addes OpenSML_Status
OpenSML_TC3.zip

In the "OpenSML_ProfilePosition" function it would be possible to add xAdditive to add a distance relative to the current position?

I'm also waiting for the Jog function and Probe.

Thanks
Massimo

Connect real Motor with example provided.

Hi!

Very nice project, but I am failing on adding my canOpen402 motor to the example.
The example uses an Axis Controller and and a Control unit - but which Axis I should use to map my motor to?

AxisController : OpenSML_AxisController;
con : OpenSML_Control;

I mapped the motor to con and If i turn the motor manually the actual position in the VISU changes - so that works.
But the rest doesnt work.

con.xSimulation:=FALSE;

I changed this to false as I am using a real motor.

Check my screenshot, I guess my mapping is wrong?

Thanks a lot!!

SML

CSP, MoveAbsolute and Jerk softmotion discuss

Hi

I'm coding with codesys a long time, i had use it to make some industrial controller, fieldbus adapter, cnc machine etc. I think i already known some principle about logical and softmotion function block.

But when i know more, i think the motion planning calc is very difficutily for me. For example, the real machine need s-curve acceleration or jerk planning, Normally just use function block like MC_MoveAbsolute and select velocity ramp mode in codesys, But i dont known how it calc position and speed in jerk motion. For now i can only realize trapezpid velocity ramp.
Then i had digger some information about motion planning... And i cannot found any plc core code about softmotion, they have a consensus that hide sourcecode. The closest is a paper about 4th order real-time trajectory generation function but no lucky to get sourcecode. Also no lucky in plcopen-motion public document.

Another way is fake a axis, due to define AXIS_REF_SM3 and make some patch like following, it bypass softmotion license and can be use MC_MoveAbsolute with full jerk funcion. Maybe i can do more work for it?

Please post any idea about this, Thanks.

Axis1:AXIS_REF_SM3;


Axis1.bCommunication:=TRUE;
Axis1.bRegulatorRealState:=TRUE;
Axis1.bDriveStartRealState:=TRUE;
IF Axis1.nAxisState=0 THEN
	Axis1.nAxisState:=3;
END_IF

Axis1.eRampType:=2;
Axis1.fSavePosition:=Axis1.fSetPosition;
Axis1.fCycleTimeSpent:=0;
Axis1.fTaskCycle:=0.001;

Some helped link:
1, codesys velocity ramp
2, Programming S-curve motion profiles
3, S-Curve acceleration?
4, ISG-MC_MoveAbsolute
5, TML-LIB_S7

Do you have any plan to make CSP mode?

Thank you for your sharing your code.
it is very helpful.

But do you have any plan to make CSP mode? Cyclic sync position mode.
I think the CSP(Point to point) is more important compared with Profile Position mode.
it will not depend on the servo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.