DemonstrateTam
function DemonstrateTam(topo,linkAddress,driveAddress,tiobAddress)
%DEMONSTRATETAM shows some of the most often used functionality.
%
% DEMONSTRATETAM
% - reads and writes registers.
% - does some motion.
% - acquires and plots some data.
% - accesses the FPGA local-bus (advanced).
%
% DEMONSTRATETAM does not
% - check for errors in general.
%
% DEMONSTRATETAM(T,LADR,DADR,TADR) shows the demo using the TAM topology
% T. Within the topology, it uses the Tria-Link with address LADR. Within
% the Tria-Link, it uses the drive with address DADR, and the I/O board
% with address TADR.
% LADR, DADR and optionally TADR are to be passed as strings.
% LADR must be absolute while DADR and TADR may be specified relatively
% to LADR.
%
% See also SETUPTAM, LOADTAM.
% $Id: DemonstrateTam.m 18279 2014-08-26 07:19:27Z chm $
% Copyright © 2011 Triamec Motion AG, Switzerland
%% Register some packages
import System.*
import System.IO.*
import Triamec.Tam.*
import Triamec.Tam.Configuration.*
import Triamec.Tam.Periphery.*
import Triamec.TriaLink.*
import Triamec.Tam.Modules.*
import Triamec.Tam.Requests.*
%% Find TAM nodes to work with
linkUri = Uri(linkAddress);
driveUri = Uri(linkUri, driveAddress);
if nargin > 3
tiobUri = Uri(linkUri, tiobAddress);
end
% Navigate down the hierarchy. .NET indexers are available as Item
% function.
%adapter = system.Item(0);
%link = adapter.Item(0);
%station = link.Item(0);
%device = station.Item(0);
% Alternative: navigate to an address as defined in the TAM
% configuration file.
device = topo.FindTamNode(driveUri);
if nargin > 3
tiob = topo.FindTamNode(tiobUri);
end
station = device.Station;
axis = device.Axes.Item(0);
axisReg = device.Register.Axes.Item(0);
%% Register a state observer to the device.
% This enables the usage of the WaitForTermination methods below
observer = System.Object;
device.AddStateObserver(observer);
%%
try
%% Enable Endat
% endatControl = EndatControl(axis);
% endatControl.SetToPositionControlModeUsingEndat;
%% Work with drive
% Set drive operational
% and wait until the request has terminated.
WaitForTermination(device,device.SwitchBridgePower(BridgePowerSwitch.On),'Bridge enable failed');
% Enable axis
WaitForTermination(device,axis.Control(AxisControlCommands.ResetErrorAndEnable),'Axis enable failed');
% Move and wait until the move has terminated
WaitForTermination(device,axis.MoveRelative(Float40.FromDouble(45)),'Move failed');
%% Work with registers
% Write velocity
axisReg.Parameters.PathPlanner.VelocityMaximum.Write(20);
% Need to commit changed parameters
axisReg.Parameters.PathPlanner.Commit;
% Read Float40 register (only position registers are typically Float40)
display(['Actual position: ', num2str(Float40.ToDouble(axisReg.Signals.PositionController.ActualPosition.Read))]);
% Read float register
if nargin > 3
display(['TIOB Analog input 1: ', num2str(tiob.Register.General.Signals.AnalogInput1.Read), 'V']);
end
%% Acquire some signals
% import all classes from the Acquisition namespace
import Triamec.Tam.Acquisitions.*
% create acquisition parameters without trigger and fastest possible sampling rate
samplingTime = TimeSpan(double(TimeSpan.TicksPerSecond)/50000);
sampleCount = 500000;
samplingDuration = samplingTime.TotalSeconds * sampleCount;
% create the variable to acquire
variable = CreateVariable(axisReg.Signals.General.ActualCurrentA, samplingTime);
% create a trigger signal (only when not acquiring unconditionally)
% trigger = TamTrigger(axisReg.Signals.PathPlanner.Done, ...
% PublicationCommand.FallingEdge, TamValue32.FromBool(true));
% alternative: subscribe a stimulus in order to start the acquisition
% (requires MATLAB R2010b)
% trigger = TamTrigger(axisReg.Signals.PathPlanner.Done, ...
% PublicationCommand.FallingEdge, TamValue32.FromBool(true), ...
% Stimulus(@() MoveRelative(axis, 20)), ...
% TimeSpan.FromSeconds(1));
% do acquiring
Acquire(variable, samplingDuration);
% alternative: with trigger:
% Acquire(variable, samplingDuration, trigger);
% alternative to acquire multiple variables synchronized
% twoVars = NET.createArray('Triamec.Tam.Acquisitions.ITamVariable', 2);
% twoVars(1) = variable1;
% twoVars(2) = variable2;
% acquisition = TamAcquisition.Create(twoVars);
% acquisition.Acquire(samplingDuration, trigger);
% acquisition.Dispose;
% copy result
data = GetDataFromVariable(variable);
% get actual sample time (should equal the samplingTime variable)
d = variable.SamplingTime.TotalSeconds;
% plot
t = 0:d:d*(sampleCount-1);
plot(t, data);
xlabel('t [s]');
%% Access periphery (FPGA local-bus)
% Make sure the specific local-bus device exists on the adapter
if station.Periphery.Contains(PeripheryDeviceIdentification.Pwm)
pwmDevice = station.Periphery.GetDevice(PeripheryDeviceIdentification.Pwm);
% create a periphery register on the fly, using information from
% the FPGA data sheet. PWM, address 3 = whether economic mode is
% enabled.
% Other Types: Periphery-UInt,-MInt,-SInt,-Float
reg = PeripheryBool(pwmDevice,'Economic Mode','',PeripheryAccess.ReadWrite,3,0);
if(reg.ReadValue)
disp('Economic PWM mode enabled.');
else
disp('Economic PWM mode not enabled.');
end
else
disp('No PWM local-bus device found this station -> cannot demonstrate periphery.');
end
DisplayDriveState(device);
%% Power off
axis.Control(AxisControlCommands.Disable).WaitForTermination;
device.SwitchBridgePower(BridgePowerSwitch.Off).WaitForTermination;
catch ME
device.RemoveStateObserver(observer);
rethrow(ME);
end
% give back resources
device.RemoveStateObserver(observer);