Axis Configration header

This page contains the complete code of the header file in this chapter.

In RT_Project_01.h, your code should be like this:

#pragma once
//This define will deprecate all unsupported Microsoft C-runtime functions when compiled under RTSS.
//If using this define, #include <rtapi.h> should remain below all windows headers
//#define UNDER_RTSS_UNSUPPORTED_CRT_APIS

#include <SDKDDKVer.h>

#include <stdio.h>
#include <string>
//#include <ctype.h>
//#include <conio.h>
//#include <stdlib.h>
//#include <math.h>
//#include <errno.h>
#include <windows.h>
#include <tchar.h>
#include <rtapi.h>    // RTX64 APIs that can be used in real-time and Windows applications.

#ifdef UNDER_RTSS
#include <rtssapi.h>  // RTX64 APIs that can only be used in real-time applications.
#include <ksapi.h>
#include <ksmotion.h>
#endif // UNDER_RTSS

 

In AxisConfiguration.h, your Axis Configuration code should be like this:

#pragma once

/* Unit Conversion */
//Desired number of units per axis revolution.
//Here we convert the unit to degrees.
#define UNITS_PER_REVOLUTION 360

/* Motion Profile */
//Units used for Acceleration and Jerk.
//profileUnitPerSecond: Acceleration in unit per second^2, Jerk in unit per second^3.
//profileDelayInSecond: Acceleration and Jerk in second.
#define MOTION_PROFILE_TYPE profileUnitPerSecond

//The axis is considered In Target when the following error is less than this value.
#define MINIMUM_ERROR 3

//The system considers it fails to control the axis when the following error is greater than this value.
//The axis will be disabled and in Error state with error 0x3005.
#define MAXIMUM_ERROR 360

//Maximum velocity used during the interpolation.
#define MAXIMUM_VELOCITY 3600

//Maximum acceleration used during the interpolation.
#define MAXIMUM_ACCELERATION 36000

//Maximum deceleration used during the interpolation.
#define MAXIMUM_DECELERATION 36000

//Maximum jerk used during the interpolation.
//Setting this value to zero will result in a T-Curve interpolation.
#define MAXIMUM_JERK 3600000

//Maximum jolt used during the interpolation.
//This is a placeholder for this value, which is not used.
#define MAXIMUM_JOLT 0

/* Velocity PID */
/*We do not provide the Torque PID sample as there are no default values
in torque modes. The axes needs to be tuned.*/
//Communication delay used for the error calculation.
//With DC enabled the normal value for EtherCAT is 3 cycles.
#define FEEDBACK_DELAY 3

//Proportional Gain.
#define KP 1

//Integral Gain.
#define KI 0

//KI Term Limit.
//Percent for Torque and Percent of MaxOutput for Velocity.
#define KI_LIMIT_PERCENT 0

//Derivative Gain.
#define KD 0

//Velocity Feedforward Gain.
#define KV 1

//Acceleration Feedforward Gain.
#define KAA 0.003

//Deceleration Feedforward Gain.
#define KAD 0.003

//Jerk Feedforward Gain.
#define KJ 0

//Delay in Seconds after which the reduced gain factor is applied to KP and KD terms.
#define REDUCED_GAIN_DELAY 0.2

//Factor applied to the KP and KD terms after the delay expired.
#define REDUCED_GAIN_FACTOR 0.1

//Only apply the KI term after the interpolation is done.
#define KI_STOPPED_ONLY TRUE

//Used the secondary encoder to calculate the error used by the KD term.
#define KD_USE_INTERNAL_ENCODER FALSE  

//The drive will not move if its velocity is less than this value.
//This is only useful in velocity control modes if the drive clamps small velocity to zero.
#define MINIMUM_OUTPUT 0

//Maximum value sent to the drive.
#define MAXIMUM_OUTPUT 5000	

//Enable monitoring of maximum error of the position lag.
#define POSITION_LAG_MONITORING FALSE

/* Safety */
//Soft Limit switch
#define ENABLE_SOFTLIMIT_POSITIVE TRUE
#define ENABLE_SOFTLIMIT_NEGATIVE TRUE

//The position of the positive software limit switch.
#define SOFT_LIMIT_POSITIVE 15000

//The position of the negative software limit switch.
#define SOFT_LIMIT_NEGATIVE -15000

//Limit sensors
//Type of module containing the max sensor.
//TRUE for axis, FALSE for I/O module.
#define MAX_SENSOR_TYPE FALSE

//Index of an axis/module containing the sensor.
#define MAX_SENSOR_INDEX 0

//Offset of the sensor in the module input data.
#define MAX_SENSOR_OFFSET 0

//Invert the max sensor value.
#define MAX_SENSOR_INVERT FALSE

//Enable the max sensor value.
#define MAX_SENSOR_ENABLE TRUE

//Type of module containing the min sensor.
//TRUE for axis, FALSE for I/O module.
#define MIN_SENSOR_TYPE FALSE

//Index of an axis/module containing the sensor.
#define MIN_SENSOR_INDEX 0

//Offset of the sensor in the module input data.
#define MIN_SENSOR_OFFSET 0

//Invert the min sensor value.
#define MIN_SENSOR_INVERT FALSE

//Enable the min sensor value.
#define MIN_SENSOR_ENABLE TRUE

VOID PrintDeviceInformation(int Index);
VOID PrintAxisInformation(int Index);
VOID PrintMotionStates(int Index);
VOID GetAvailableControlMode(int Index);
VOID SetControlMode(int Index);
VOID MotionProfile(int Index);
VOID PositionUnitConversion(int Index);
VOID SoftLimitSwitch(int Index);
VOID LimitSensor(int Index);
VOID LimitDirection(int Index);
VOID UpdatePID(int Index);