Help with code to s...
 
Notifications
Clear all

Help with code to synchronize two motors using firmware 4.15C

5 Posts
1 Users
0 Reactions
12.3 K Views
(@jhon.possu)
Posts: 3
New Member Guest
Topic starter
 

Hi Everyone,

We have 2 SmartMotors with firmware version 4.15C. We need the motors to perform a raster scan meaning moving from point to point in the XY plane until they complete the trajectory. The PC is not available to control the trajectory.

I am trying to synchronize the motors by creating handshake using variables that are set/reset when the motors complete certain tasks, like finishing a trajectory. This is a small code that I wrote to test the idea. The addresses for the motor have been set-up and I am downloading the same program to both motors.

IF ADDR==1
a=1
WHILE a<10 'just want to loop a few types to see if it works.
f=1 'keeps motor 1 in the loop until it gets the signal from motor 2
PRINT(#130,"w=1 ",#13) 'command motor 2 to move
WHILE f==1 LOOP
PRINT("Exited Loop",#13) 'For debugging only
WAIT=4000
a=a+1
LOOP
ENDIF

IF ADDR==2
A=100
V=100000
O=0
G
w=0
WHILE 1
IF w==1 'if w is set by motor 1, calls the subroutine that moves the motor.
GOSUB7
ENDIF
LOOP

C7
D=100
G
TWAIT
RP 'for debugging only
w=0 'reset w, it needs to be set again by command from motor 1
PRINT(#129,"f=0 ",#13) 'once the trajectory finishes reset f so motor 1 knows about it
RETURN
ENDIF
END

The problem is that the program only works when I set the variables using SMI.
Any ideas or suggestions are welcome.

Thank you very much in advanced.

 
Posted : 18/10/2012 1:39 pm
(@csearcy)
Posts: 0
New Member Guest
 

You've taken a good approach. Here are two "catches" though.
1. RS232 can only talk downstream. Motor1 can talk to motor2... but motor2 can't talk to motor1.
2. RS485 between the motors lets either motor send values, etc. to the other motor. The catch is they can transmit at the same time and both of the commands get corrupted. You have to let one be the Master to prevent collision.

'RS485 is your best bet with 4.15C firmware.
'Connect 5-5, 6-6, and 13-13 on the 15pin DSub connector then open the RS485 ports and set addresses
OCHN(RS4,1,N,19200,1,8,C)
SADDR1 'or SADDR2... Use PRINT1 instead of PRINT to access the RS485 port.
END

Note: You also have encoder following and camming that can be used if needed.

 
Posted : 18/10/2012 11:00 pm
(@jhon.possu)
Posts: 3
New Member Guest
Topic starter
 

Thank you very much for the prompt reply.

I am going to use the RS-485.
Can you be a little more specific about the Master part to prevent collision? Do you have an example that can provide that illustrate the issue of synchronize movement?

Thanks again.

 
Posted : 19/10/2012 11:17 am
(@csearcy)
Posts: 0
New Member Guest
 

I don't have a code example for 4.15C... but here's the approach. This isn't really synchronized movement like our Class5 Combitronic protocol... but you can do what appears to be simultaneous departure and arrival... with confirmation when the other axis completes it's move.
Let Motor1 be the Master. Motor2 should NOT do PRINT1 commands... unless Motor1 sends something to make Motor2 respond... like...

a=0
MP A=100 V=10000 D=2000 G
PRINT1(#130,"GOSUB10",#13)
WHILE a==0 LOOP
'...more Master (Motor1) code executes when variable a==1...

... then the Slave (Motor2) C10 subroutine could be...

C10
'do something Motor1 wants you to do...
MP A=100 V=10000 D=2000 G TWAIT
PRINT1(#129,"a=1",#13)
RETURN

Meanwhile... The Motor1 program loops... waiting for it's variable "a" to be equal to 1.

 
Posted : 19/10/2012 8:26 pm
(@jhon.possu)
Posts: 3
New Member Guest
Topic starter
 

Thank you very much for the thorough explanation.

 
Posted : 20/10/2012 2:56 pm
Share: