Camming.cs

Simple cam motion

/*  
 Copyright(c) 1998-2009 by Robotic Systems Integration, Inc. All rights reserved.
 This software contains proprietary and confidential information of Robotic 
 Systems Integration, Inc. (RSI) and its suppliers. Except as may be set forth 
 in the license agreement under which this software is supplied, disclosure, 
 reproduction, or use with controls other than those provided by RSI or suppliers
 for RSI is strictly prohibited without the prior express written consent of 
 Robotic Systems Integration.

 Warning!  This is a sample program to assist in the integration of your motion 
 controller with your application.  It may not contain all of the logic and safety
 features that your application requires.

 For any questions regarding this sample code please visit www.roboticsys.com.
 ==================================================================================
*/

using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using RSI.RapidCode.SynqNet.dotNET;
using RSI.RapidCode.SynqNet.dotNET.Enums;

namespace SampleApplications
{
    [TestFixture]
    public class Camming
    {
        const int MASTER_AXIS_NUMBER = 2;
        const int SLAVE_AXIS_NUMBER = 3;

        const double master_velocity = 100;
        const double master_accel = 1000;
        
        double[] masterDistances = { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 };
        double[] slavePositions = { 90, 54, 36, 42, 46, 97, 34, 83, 63, 86, 60, 86, 63, 83, 34, 97, 46, 42, 36, 54, 90 };
 
        MotionController mc;
        Axis master;
        Axis slave;

        [SetUp]
        public void Setup()
        {
            mc = MotionController.Create();
            master = mc.AxisGet(MASTER_AXIS_NUMBER);
            slave = mc.AxisGet(SLAVE_AXIS_NUMBER);

            master.ClearFaults();
            slave.ClearFaults();

            master.AmpEnableSet(true);
            slave.AmpEnableSet(true);
            slave.PositionSet(0);  // this negates homing, so only do it in test/sample code
        }

        [Test]
        public void CammingTest()
        {
            // command motion on the slave before the master starts
            slave.MoveCamLinear(master.NumberGet(), RSIAxisMasterType.RSIAxisMasterTypeAXIS_COMMANDED_POSITION, masterDistances, slavePositions, masterDistances.Length);

            // command a constant velocity on the master axis, slave will follow
            master.MoveVelocity(master_velocity, master_accel);

            // wait for the cam motion to complete
            slave.MotionDoneWait();

            // stop the master
            master.Stop();
        }
    }
}