Difference between revisions of "Program Examples:Create Motion:CAM Table"

From SoftMC-Wiki
Jump to: navigation, search
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
{{Languages|Program_Examples:Create_Motion:CAM_Table}}
 
The following example demonstrates how to create and use a CAM table.<br/>
 
The following example demonstrates how to create and use a CAM table.<br/>
 
Refer to [[Axis_Setup_Procedure|Axis Setup Procedure]] for an explanation and an example of how to set up an axis.<br/>
 
Refer to [[Axis_Setup_Procedure|Axis Setup Procedure]] for an explanation and an example of how to set up an axis.<br/>
 +
[[File:CAM_MOVE.PNG|250px]]
  
 
<syntaxhighlight lang="vb">
 
<syntaxhighlight lang="vb">
Line 18: Line 20:
  
 
'Declaring a cam-table type global variable:
 
'Declaring a cam-table type global variable:
 +
common shared AX_MASTER as generic axis = A1
 +
common shared AX_SLAVE as generic axis = A2
 
common shared CamTable1 as cam
 
common shared CamTable1 as cam
  
Line 86: Line 90:
  
 
'Creating an empty cam table:
 
'Creating an empty cam table:
'This table is cyclic:
+
'This table is cyclic (infinite cycle repetitions):
 
CamTable1.Cycle = -1
 
CamTable1.Cycle = -1
  

Latest revision as of 01:46, 17 July 2017

Language: English  • 中文(简体)‎

The following example demonstrates how to create and use a CAM table.
Refer to Axis Setup Procedure for an explanation and an example of how to set up an axis.
CAM MOVE.PNG

'**********************************************************************************************************
' File:			CAM_MOVE.PRG
' Purpose:		Move two axes with CAM table and master-slave
' Version:		1.00
' Author:		Nir Geller
' Description:	This is an example of use of a CAM table. Initialize a CAM table with a sinus function character,
'				and set master - slave relations between two axes. Move the master axis and see how the slave axis
'				follows according to the cam table.
'
'				Record or watch the PFB of AX_MASTER and AX_SLAVE.
'
'**********************************************************************************************************

'Declaring a cam-table type global variable:
common shared AX_MASTER as generic axis = A1
common shared AX_SLAVE as generic axis = A2
common shared CamTable1 as cam

program

	call SetCAM

 
	attach AX_MASTER
	attach AX_SLAVE

 
	'call EC_SET_MOTION_OPMODE(AX_MASTER, POSITIONMODE)

 
	AX_MASTER.en = 1
	AX_SLAVE.en = 1
 
	sleep 1000
 
	while 1
 
		MOVE AX_MASTER 1000 vcruise=1000 starttype=immediate abs = 1

 
		while AX_MASTER.IsMoving <> 0
			sleep 1000
		end while
 

 
		MOVE AX_MASTER 0 vcruise=1000 starttype=immediate abs = 1

 
		while AX_MASTER.IsMoving <> 0
			sleep 1000
		end while
 
 
	end while
 
	detach AX_MASTER
	detach AX_SLAVE

end program




'****************************************************************************
' Subroutine Name: SetCAM
' Description: Initialize a CAM table with a sinus function character, and set
'				master - slave relations between two axes.
' Called From: Program
' Author: Nir Geller
' Input Parameters: None
' Output Parameters: None
' Return Value: None
' Algorithm:
' Global Variables Used:
' Revisions:
'****************************************************************************
sub SetCAM

	dim camsize as long = 10000
	dim cam_amplitude as long = 100
	dim i as long = 0

	'Creating an empty cam table:
	'This table is cyclic (infinite cycle repetitions):
	CamTable1.Cycle = -1

	'Not linked to any other cam-tables:
	CamTable1.Next = none
	CamTable1.Prev = none

	'Making it 10000 points
	createcamdata camsize CamTable1

	'Defining a 360 deg sine table:
	for i = 1 to CamTable1.Size 
		CamTable1.MasterData [i] = 360*(i-1)/CamTable1.Size ' Master in degrees
		CamTable1.SlaveData  [i] = cam_amplitude *sin (CamTable1.MasterData [i] * pi/180)
	next

	'Store the newly created file onto flash disk:
	storecamdata ct1.cam CamTable1

	'Once the table is stored on the flash it can be reloaded as:
	'loadcamdata ct1.cam CamTable1

	print "CAM table set"

	attach AX_MASTER
	attach AX_SLAVE

		AX_SLAVE.MasterSource = AX_MASTER.PCMD
		AX_SLAVE.GearRatio = 1.0
		AX_SLAVE.CamOffset = 0 
		AX_SLAVE.FirstCam  = CamTable1 
		AX_SLAVE.slave     = cam

	detach AX_MASTER
	detach AX_SLAVE

	print "Master-Slave relation set"

end sub


The example corresponds to commit SHA-1: 6b843ca272c3e3d28d36d7116ba9812f4166d97f in GIT.


See Also