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

Connect real Motor with example provided. #7

Closed
nonpostrans opened this issue Jul 12, 2024 · 7 comments
Closed

Connect real Motor with example provided. #7

nonpostrans opened this issue Jul 12, 2024 · 7 comments

Comments

@nonpostrans
Copy link

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

@feecat
Copy link
Owner

feecat commented Jul 15, 2024

Hi,
Mapping seems fine. I had noticed that controlword = 4, it means axis not enable. Try click "enable" button on visulization or set con.xAxisEnable?

@nonpostrans
Copy link
Author

nonpostrans commented Jul 15, 2024

Hi!
My current program looks like that:

AxisController(Axis:=con.axis , Control:=con);
con.xSimulation:=FALSE;
con.xAxisEnable := TRUE;
con.xEnabled := TRUE;

I realized that when I set con.xMoveEnable via the GUI con.xError till turn to TRUE, so an error state.
I checked the state machine of AxisController and I think in is this line:

ELSIF Control.xMoveEnable AND Axis.StatusWord.1 AND Axis.Modes_of_operation_display <> 8 THEN//need switch mode

Condition is never met because Axis.StatusWord.1 is not true. Bit one is "Switched On" but where is the state machine put into that state? Maybe I am also wrong.

Controlword changed to 6.

Thanks for your support!

sml3
sml1

@feecat
Copy link
Owner

feecat commented Jul 16, 2024

Hi,

xAxisEnable should set before xMoveEnable, ControlWord control by OpenSML_Power.
In you screenshoot i can see controlword = 6, means control.2 and control.1 is TRUE. You can check OpenSML_Power, it should into step 20 but why not go 30? Could you upload your project file?

image

BTW, if you use opensml, please remove axis in device tree. otherwise process data could be overwrite.

@nonpostrans
Copy link
Author

Hello!
Now it is working, thank you.
However, I want to use ProfilePosition mode and I dont understand how to put the motor in operation properly.
I connected con.xAxisEnable and con.xMoveEnableand MC_Linear.xEnable to GUI switches for testing.
If I manually turn on xAxisEnable, then xMoveEnable and after that enable ProfilePosition FB with xEnable it works. I can execute movement on the real motor.

Now I want to use a state machine to do this:

VAR
	AxisController : OpenSML_AxisController;
	MC_Linear : OpenSML_ProfilePosition;
        Home_X : OpenSML_Home;
	con : OpenSML_Control;
	iState : INT := 0;
END_VAR
AxisController(Axis:=con.axis , Control:=con);
con.xSimulation:=FALSE;

CASE iState OF
	
	0: con.xAxisEnable := TRUE; 
		IF con.xEnabled THEN. //<- Condition never true
			con.xMoveEnable := TRUE;
			MC_Linear.xEnable := TRUE;
			iState:=10;
		END_IF
	
	10:	
		//Home_X(Axis:=con.Axis);
		iState:=20;
END_CASE

con.xEnabled will not switch to TRUE.
I dont know, maybe I need to wait until communication with the motor is established before setting con.xAxisEnable := TRUE;

Thanks for your support!

@feecat
Copy link
Owner

feecat commented Jul 19, 2024

Hi,
Currently most servo driver that use ethercat protocol is cia402 standard, it means driver work on CSP mode default.
If you controller have enough real-time performance, you should use CSP mode.

If you really want use PP( ProfilePosition), you need modify pdo data, enable profile position/ target velocity/ modes of operation. I had notice that your screenshot already config ok, thats good.
You should config ACC/DEC, Speed curve, filter etc on servo driver when use PP mode.
AxisController is a demo with CSP. If you want use PP, you sould use that code:

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

@nonpostrans
Copy link
Author

Hi!

Due to several reasons I don't want to use CSP mode, although I know that this is the key functionality of this library.

However I found a bug in OpenSML_ProfilePosition

IF xEnable AND Axis.StatusWord.1 AND Axis.StatusWord.2 AND Axis.Modes_of_operation_display = 3 AND NOT Axis.StatusWord.3 THEN//ready

Axis.Modes_of_operation_display = 3 is wrong because here we check for Profile Position Mode which is mode one.

Axis.Modes_of_operation_display = 1 is correct.

I am not a programmer so please double check!

Thanks for your amazing work!

@feecat
Copy link
Owner

feecat commented Jul 22, 2024

Hi,

You are right, i will fix it. Thanks you.

If you have others problem please feel free to ask.

@feecat feecat closed this as completed in f99ebdd Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants