DS Rotation
Edit this on GitLab
DS Rotation Sample Application (SSK 1.x)
Overview
The DS Rotation sample application demonstrates how to configure and control rotation mode on synchro/resolver (D/S) modules using the NAI Software Support Kit (SSK 1.x). It covers the rotation operations you will need in your own application: setting the rotation rate in degrees per second, selecting continuous or start-stop mode, configuring start and stop angles, initiating and halting rotation via software trigger, and controlling channel power.
D/S modules support hardware-driven rotation, where the module automatically sweeps the output angle at a programmed rate. This is useful for testing synchro/resolver receivers, simulating rotating machinery, or generating position profiles. The rotation can run continuously or between configurable start and stop angles. The trigger source can be internal (software) or external — this sample uses internal triggering exclusively.
This sample supports all DS module types (see the DS1-DSN Manual for module variants and specifications). It serves as a practical API reference — each menu command maps directly to one or more naibrd_DS_*() API calls that you can lift into your own code.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a DS module installed.
-
SSK 1.x installed on your development host.
-
The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.
How to Run
Launch the DS_Rotation executable from your build output directory. On startup the application looks for a configuration file (default_DsRotation.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, the application lets you select a module and channel, then configure and start rotation.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to DS. For details on board connection configuration, see the First Time Setup Guide. |
The main() function follows a standard SSK 1.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_DsRotation.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleID().
#if defined (__VXWORKS__)
int32_t Run_DS_RotationSample(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
Run_DS_Rotation(cardIndex, module, moduleID);
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiapp_access_CloseAllOpenCards();
return 0;
}
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
On standard platforms the entry point is main(). On VxWorks the entry point is Run_DS_RotationSample() — the SSK 1.x build system selects the correct variant via a preprocessor guard:
#if defined (__VXWORKS__)
int32_t Run_DS_RotationSample(void)
#else
int32_t main(void)
#endif
Initial Channel Setup
Before entering the rotation command loop, DS_SetRotation() performs essential channel initialization to prepare the channel for software-triggered rotation:
/* Set fixed output mode (output voltage is constant regardless of reference) */
check_status(naibrd_DS_SetRatioFixedMode(cardIndex, module, channel, NAI_DS_OUTPUT_FIXED));
/* Enable the channel */
check_status(naibrd_DS_SetActiveChannel(cardIndex, module, channel, NAI_ENABLE));
/* Set rotation trigger source to internal (software trigger) */
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_TRIG_SOURCE, (float64_t)NAI_DS_ROT_TRIG_INTERNAL));
/* Power on the channel */
check_status(naibrd_DS_SetPowerEnable(cardIndex, module, channel, NAI_ENABLE));
-
NAI_DS_OUTPUT_FIXED— sets the channel to fixed output mode. In rotation mode, fixed mode ensures the output amplitude stays constant as the angle sweeps. -
NAI_DS_ROT_TRIG_INTERNAL— selects software (internal) triggering. The user starts rotation by callingnaibrd_DS_SetRotationEnable(). -
The channel must be both powered on and active before rotation can start.
Command Loop
The top-level menu allows module and channel selection, and the RR command enters the rotation submenu:
| Command | Description |
|---|---|
RR |
Enter the rotation control submenu |
M |
Select module |
C |
Select channel |
Within the rotation submenu:
| Command | Description |
|---|---|
RATE |
Set rotation rate in degrees per second |
MODE |
Set rotation mode (continuous or start-stop) |
STRANG |
Set rotation start angle |
STPANG |
Set rotation stop angle |
STRROT |
Start (initiate) rotation |
STPROT |
Stop rotation |
PWER |
Set power enable/disable |
UPDATE |
Refresh the status display |
The menu-driven structure is a convenience of the sample application. In your own application, you would call the same underlying naibrd_DS_*() API functions directly.
Rotation Configuration
Set Rotation Rate
To set the rotation rate in degrees per second (DPS) in your own application, call naibrd_DS_SetRotationCtrl() with the NAI_DS_ROTATION_RATE parameter:
float64_t rateInDPS = 100.0;
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_RATE, rateInDPS));
-
cardIndex— identifies the board. -
module— the slot containing the DS module. -
channel— the channel to configure. -
NAI_DS_ROTATION_RATE— selects the rotation rate parameter. -
rateInDPS— the rotation speed in degrees per second. Negative values reverse the direction. Valid range is -1000.0 to 1000.0. Consult the DS1-DSN Manual for your module’s actual rate limits.
Set Rotation Mode
To select continuous or start-stop rotation mode:
/* Continuous mode -- angle sweeps indefinitely */
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel,
NAI_DS_ROTATION_MODE, (float64_t)NAI_DS_ROT_CONTINUOUS_MODE));
/* Start-stop mode -- angle sweeps from start to stop angle, then halts */
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel,
NAI_DS_ROTATION_MODE, (float64_t)NAI_DS_ROT_START_STOP_MODE));
-
cardIndex— identifies the board. -
module— the slot containing the DS module. -
channel— the channel to configure. -
NAI_DS_ROTATION_MODE— selects the rotation mode parameter. -
In continuous mode, the angle wraps around at 360 degrees and keeps sweeping. In start-stop mode, rotation halts when the stop angle is reached.
Set Start and Stop Angles
To set the rotation start angle (initial position) and stop angle (ending position when using start-stop mode):
float64_t startAngle = 0.0;
float64_t stopAngle = 180.0;
/* Set start angle (also serves as the initial angle position) */
check_status(naibrd_DS_SetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, startAngle));
/* Set stop angle (used only in start-stop mode) */
check_status(naibrd_DS_SetAngle(cardIndex, module, channel, NAI_DS_ANGLE_ROTATION_STOP, stopAngle));
-
cardIndex— identifies the board. -
module— the slot containing the DS module. -
channel— the channel to configure. -
NAI_DS_ANGLE_SINGLE— sets the start/current angle position. -
NAI_DS_ANGLE_ROTATION_STOP— sets the stop angle for start-stop mode. -
Angle values range from 0.0 to 359.9954 degrees.
Start and Stop Rotation
To initiate or halt rotation, call naibrd_DS_SetRotationEnable():
/* Start rotation */
check_status(naibrd_DS_SetRotationEnable(cardIndex, module, channel, 1));
/* Stop rotation */
check_status(naibrd_DS_SetRotationEnable(cardIndex, module, channel, 0));
-
cardIndex— identifies the board. -
module— the slot containing the DS module. -
channel— the channel to control. -
The fourth parameter —
1to start rotation,0to stop.
Set Power Enable
To turn power on or off for a channel:
/* Power on */
check_status(naibrd_DS_SetPowerEnable(cardIndex, module, channel, (uint8_t)NAI_ENABLE));
/* Power off */
check_status(naibrd_DS_SetPowerEnable(cardIndex, module, channel, (uint8_t)NAI_DISABLE));
|
Important
|
Common Errors
|
Reading Rotation Status
The sample displays current rotation state on each iteration of the command loop via DS_ShowSetRotationTestResult(). To read the same values in your own application:
float64_t rate, mode, measAngle, startAngle, stopAngle, trigSource;
uint32_t rotStatus;
uint8_t powerState;
/* Read rotation rate */
naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_RATE, &rate);
/* Read rotation mode */
naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_MODE, &mode);
/* Read measured angle */
naibrd_DS_GetMeasuredValue(cardIndex, module, channel, NAI_DS_MEASURED_ANGLE, &measAngle);
/* Read start angle */
naibrd_DS_GetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, &startAngle);
/* Read stop angle */
naibrd_DS_GetAngle(cardIndex, module, channel, NAI_DS_ANGLE_ROTATION_STOP, &stopAngle);
/* Read trigger source */
naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_TRIG_SOURCE, &trigSource);
/* Read rotation status */
naibrd_DS_GetRotationStatus(cardIndex, module, channel, &rotStatus);
/* Read power state */
naibrd_DS_GetPowerEnable(cardIndex, module, channel, &powerState);
-
rate— the programmed rotation speed in DPS. -
mode—NAI_DS_ROT_CONTINUOUS_MODEorNAI_DS_ROT_START_STOP_MODE. -
measAngle— the current measured angle as reported by the hardware. -
rotStatus—NAI_DS_STATUS_ROT_NOT_DONEwhen the channel is actively rotating, or a completion value when rotation has stopped. -
trigSource—NAI_DS_ROT_TRIG_INTERNALfor software trigger,NAI_DS_ROT_TRIG_EXTERNALfor external trigger. -
powerState—NAI_ENABLEif powered on,NAI_DISABLEif powered off.
Troubleshooting Reference
|
Note
|
This section summarizes errors covered in the preceding sections. Consult the DS1-DSN Manual for hardware-specific diagnostics. |
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found or connection timeout |
Board not powered, incorrect or missing configuration file, network issue |
Verify hardware is powered and connected. If |
Module not recognized at selected slot |
Slot does not contain a DS module |
Verify module installation with the board menu |
Rotation does not start |
Channel not powered, not active, trigger source not set to internal, or rotation not enabled |
Complete all four initialization steps (fixed mode, active channel, trigger source, power) then call |
Rotation rate out of range |
Value exceeds -1000.0 to 1000.0 DPS limits |
Use values within the valid range; check module manual for actual limits |
Measured angle does not change |
Rotation not enabled, or in start-stop mode and already at stop angle |
Start rotation with |
Angle values out of range |
Start or stop angle outside 0.0-359.9954 |
Correct the angle value |
Module not recognized |
Slot does not contain a DS module |
Verify module installation with the board menu |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — DS_Rotation.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <ctype.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
/* naibrd include files */
#include "DS_Common.h"
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ds.h"
#include "advanced/nai_ether_adv.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_DsRotation.txt";
/* Function prototypes */
static void Run_DS_Rotation(int32_t cardIndex, int32_t module, uint32_t moduleID);
static void Show_DSDemoFunc_Commands(void);
static void DS_SetRotation(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_ShowSetRotationTestResult(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationRate(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationMode(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationStartAngle(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetRotationStopAngle(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_StartRotation(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_StopRotation(int32_t cardIndex, int32_t module, int32_t channel);
static void DS_SetPower(int32_t cardIndex, int32_t module, int32_t channel);
static void printInvalidUserInputMessage(uint32_t uTypeIdx, float64_t dUserInput);
static void showCurrentModChan(int32_t nModule, int32_t nChannel);
static uint32_t getUserInput(void);
static bool_t checkUserInput(uint32_t uTypeIdx, float64_t dUserInput);
/****** Command Table *******/
enum dsfunc_commands
{
DS_FUNC_CMD_SET_ROTATION,
DS_FUNC_CMD_SET_MODULE,
DS_FUNC_CMD_SET_CHANNEL,
DS_FUNC_CMD_COUNT
};
/****** User Input Table *******/
enum dsfunc_userInputs
{
DS_USER_INPUT_SET_ROT_RATE,
DS_USER_INPUT_SET_ROT_MODE,
DS_USER_INPUT_SET_ROT_START_ANG,
DS_USER_INPUT_SET_ROT_STOP_ANG,
DS_USER_INPUT_INITIATE_ROTATION,
DS_USER_INPUT_STOP_ROTATION,
DS_USER_INPUT_POWER,
DS_USER_INPUT_REFRESH,
DS_USER_INPUT_QUIT,
DS_USER_INVALID_INPUT,
DS_USER_INPUT_COUNT
};
/* "what to type", "what is displayed", assigned cmd #, function called */
struct dsdemofunc_cmdtbl {
int8_t *cmdstr;
int8_t *menustr;
int32_t cmdnum;
void(*func)(int32_t cardIndex, int32_t module, int32_t channel);
};
/* assigned cmd #, uppwer Limit, lower Limit*/
struct dsUserInputLimitTable {
int32_t cmdnum;
int8_t *cmdstr;
float64_t upperLimit;
float64_t lowerLimit;
};
/****** Command Tables *******/
static struct dsdemofunc_cmdtbl DS_DemoFuncMenuCmds[] = {
{(int8_t *)"RR", (int8_t *)"Run Rotation", DS_FUNC_CMD_SET_ROTATION, DS_SetRotation},\
{(int8_t *)"M ", (int8_t *)"Select Module", DS_FUNC_CMD_SET_MODULE, NULL},\
{(int8_t *)"C ", (int8_t *)"Select Channel", DS_FUNC_CMD_SET_CHANNEL, NULL},\
{NULL, NULL, 0, NULL}
};
/****** User Input Command Tables *******/
static struct dsdemofunc_cmdtbl DS_DemoUserInputs[] = {
{(int8_t *)"RATE", (int8_t *)"Set Rotation Rate", DS_USER_INPUT_SET_ROT_RATE, DS_SetRotationRate},
{(int8_t *)"MODE", (int8_t *)"Set Rotation Mode", DS_USER_INPUT_SET_ROT_MODE, DS_SetRotationMode},
{(int8_t *)"STRANG", (int8_t *)"Set Rotation Start Angle", DS_USER_INPUT_SET_ROT_START_ANG, DS_SetRotationStartAngle},
{(int8_t *)"STPANG", (int8_t *)"Set Rotation Stop Angle", DS_USER_INPUT_SET_ROT_STOP_ANG, DS_SetRotationStopAngle},
{(int8_t *)"STRROT", (int8_t *)"Start Rotation", DS_USER_INPUT_INITIATE_ROTATION, DS_StartRotation},
{(int8_t *)"STPROT", (int8_t *)"Stop Rotation", DS_USER_INPUT_STOP_ROTATION, DS_StopRotation},
{(int8_t *)"PWER", (int8_t *)"Set Power", DS_USER_INPUT_POWER, DS_SetPower},
{(int8_t *)"UPDATE", (int8_t *)"Update", DS_USER_INPUT_REFRESH, NULL},
{(int8_t *)"Q", (int8_t *)"Quit", DS_USER_INPUT_QUIT, NULL},
{(int8_t *)"", (int8_t *)"", DS_USER_INVALID_INPUT, NULL},
{NULL, NULL, 0, NULL}
};
static struct dsUserInputLimitTable DS_Inputs_Limits[] = {
{DS_USER_INPUT_SET_ROT_RATE, (int8_t *)"Rot. Rate", 1000.0, -1000.0 },
{DS_USER_INPUT_SET_ROT_MODE, (int8_t *)"Rot. Mode", 1.0, 0.0 },
{DS_USER_INPUT_SET_ROT_START_ANG, (int8_t *)"Rot. Start Angle", 359.9954, 0.0 },
{DS_USER_INPUT_SET_ROT_STOP_ANG, (int8_t *)"Rot. Stop Angle", 359.9954, 0.0 },
{DS_USER_INPUT_INITIATE_ROTATION, (int8_t *)"Start Rot", 1.0, 0.0 },
{DS_USER_INPUT_STOP_ROTATION, (int8_t *)"Stop Rot.", 1.0, 0.0 },
{DS_USER_INPUT_POWER, (int8_t *)"Set Power", 1.0, 0.0 },
{DS_USER_INPUT_QUIT, (int8_t *)"", 0.0, 0.0 },
{DS_USER_INVALID_INPUT, (int8_t *)"", 0.0, 0.0 },
{DS_USER_INPUT_COUNT, (int8_t *)"", 0.0, 0.0 }
};
#if defined (__VXWORKS__)
int32_t Run_DS_RotationSample(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
Run_DS_Rotation(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
static void Run_DS_Rotation(int32_t cardIndex, int32_t module, uint32_t moduleID)
{
bool_t bQuit;
int32_t channel = 0;
int32_t MaxModule = 0;
int32_t MaxChannel = 0;
int32_t cmdIdx;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get the number of D/S channels on the module */
moduleID = naibrd_GetModuleID(cardIndex, module);
MaxChannel = naibrd_DS_GetChannelCount(moduleID);
/*Show data*/
do
{
Show_DSDemoFunc_Commands();
printf("\nType DS command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
for (cmdIdx = 0; cmdIdx < DS_FUNC_CMD_COUNT; cmdIdx++)
{
if (0 == naiapp_strnicmp((const int8_t*)inputBuffer, (const int8_t*)DS_DemoFuncMenuCmds[cmdIdx].cmdstr, inputResponseCnt))
break;
}
switch (cmdIdx)
{
case DS_FUNC_CMD_SET_ROTATION:
if ((module > 0) && (channel > 0))
DS_SetRotation(cardIndex, module, channel);
break;
case DS_FUNC_CMD_SET_MODULE:
printf("\nEnter Module Number:\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
module = atoi((const char *)inputBuffer);
if ((module < 1) || (module > MaxModule))
{
printf("\n%s: %d is outside the limits[%d - %d]", "Module #", module, 1, MaxModule);
}
break;
case DS_FUNC_CMD_SET_CHANNEL:
printf("\nEnter Channel Number:\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
channel = atoi((const char *)inputBuffer);
if ((channel < 1) || (channel > MaxChannel))
{
printf("\n%s: %d is outside the limits[%d - %d]", "Channel #", channel, 1, MaxChannel);
}
break;
default:
break;
}
}
} while (bQuit == FALSE);
}
static void Show_DSDemoFunc_Commands(void)
{
int i;
printf("\n\t\t DS Rotation Menu");
printf("\n\t\t ================\n");
printf("\n\nCommands");
printf("\n--------");
for (i = 0; i < DS_FUNC_CMD_COUNT && DS_DemoFuncMenuCmds[i].cmdstr != NULL; i++)
printf("\n%s\t%s", DS_DemoFuncMenuCmds[i].cmdstr, DS_DemoFuncMenuCmds[i].menustr);
printf("\n");
}
static void Show_Rotation_UserInput_Commands(void)
{
int i;
printf("\n\t\t Rotation User Inputs\n ");
printf("\n\nCommands");
for (i = 0; i < DS_USER_INPUT_COUNT && DS_DemoUserInputs[i].cmdstr != NULL; i++)
printf("\n%s\t%s", DS_DemoUserInputs[i].cmdstr, DS_DemoUserInputs[i].menustr);
printf("\n");
}
static void DS_SetRotation(int32_t cardIndex, int32_t module, int32_t channel)
{
uint32_t udUserInput;
bool_t bYes = FALSE;
printf("\n================================================================");
printf("\nThis program puts the specific D/S channel in roation mode.");
printf("\nThe user can set the following rotation attributes:");
printf("\n1. Rotation Rate.");
printf("\n2. Rotation Mode (Continuous / Start-stop).");
printf("\n3. Rotation Start Angle");
printf("\n4. Rotation Stop Angle");
printf("\n5. Initiate Rotation");
printf("\n6. Stop Rotation");
printf("\n7. Set Module Power");
printf("\nThe rotation trigger source is set to internal(software trigger) ");
printf("\nand the user can query the current rotation state.\n");
printf("\n================================================================");
check_status(naibrd_DS_SetRatioFixedMode(cardIndex, module, channel, NAI_DS_OUTPUT_FIXED));
check_status(naibrd_DS_SetActiveChannel(cardIndex, module, channel, NAI_ENABLE));
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_TRIG_SOURCE, (float64_t)NAI_DS_ROT_TRIG_INTERNAL));
check_status(naibrd_DS_SetPowerEnable(cardIndex, module, channel, NAI_ENABLE));
do
{
DS_ShowSetRotationTestResult(cardIndex, module, channel);
showCurrentModChan(module, channel);
Show_Rotation_UserInput_Commands();
udUserInput = getUserInput();
switch (udUserInput)
{
case DS_USER_INPUT_SET_ROT_RATE:
case DS_USER_INPUT_SET_ROT_MODE:
case DS_USER_INPUT_SET_ROT_START_ANG:
case DS_USER_INPUT_SET_ROT_STOP_ANG:
case DS_USER_INPUT_INITIATE_ROTATION:
case DS_USER_INPUT_STOP_ROTATION:
case DS_USER_INPUT_POWER:
DS_DemoUserInputs[udUserInput].func(cardIndex, module, channel);
break;
case DS_USER_INPUT_QUIT:
bYes = TRUE;
break;
case DS_USER_INPUT_REFRESH:
case DS_USER_INVALID_INPUT:
break;
}
} while (bYes == FALSE);
}
static void DS_ShowSetRotationTestResult(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
uint32_t unValue = 0;
uint8_t u8Value = 0;
printf("\nRot. Rate Rot. Mode Meas. Ang Start Angle Stop Angle Rot. Source Rot. State Power ");
printf("\n---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------\n");
/*get rotation rate*/
check_status(naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_RATE, &dValue));
printf("%-15.4f", dValue);
/*get rotation Mode*/
check_status(naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_MODE, &dValue));
if ((nai_ds_rotation_mode_t)dValue == NAI_DS_ROT_CONTINUOUS_MODE)
printf("%-15s", DS_ROTATION_CONTINUOUS);
else
printf("%-15s", DS_ROTATION_START_STOP);
/*get measured angle*/
check_status(naibrd_DS_GetMeasuredValue(cardIndex, module, channel, NAI_DS_MEASURED_ANGLE, &dValue));
printf("%-15.4f", dValue);
/*get rotation Start Angle*/
check_status(naibrd_DS_GetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, &dValue));
printf("%-15.4f", dValue);
/*get rotation Stop Angle*/
check_status(naibrd_DS_GetAngle(cardIndex, module, channel, NAI_DS_ANGLE_ROTATION_STOP, &dValue));
printf("%-15.4f", dValue);
/*get rotation Source*/
check_status(naibrd_DS_GetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_TRIG_SOURCE, &dValue));
if ((nai_ds_rotation_trigger_source_t)dValue == NAI_DS_ROT_TRIG_INTERNAL)
printf("%-15s", DS_ROTATION_SRC_INT);
else if ((nai_ds_rotation_trigger_source_t)dValue == NAI_DS_ROT_TRIG_EXTERNAL)
printf("%-15s", DS_ROTATION_SRC_EXT);
else
printf("%-15s", DS_NOT_DEFINED);
/*get rotation State*/
check_status(naibrd_DS_GetRotationStatus(cardIndex, module, channel, &unValue));
if (unValue == NAI_DS_STATUS_ROT_NOT_DONE)
printf("%-15s", DS_ROTATION_STATUS_ROTATING);
else
printf("%-15s", DS_ROTATION_STATUS_NOT_ROTATING);
/*get power State*/
check_status(naibrd_DS_GetPowerEnable(cardIndex, module, channel, &u8Value));
if (u8Value == NAI_ENABLE)
printf("%-15s", DS_ENABLE);
else
printf("%-15s", DS_DISABLE);
printf("\n");
}
static void DS_SetRotationRate(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter Rotation Rate(DPS)\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_RATE, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_RATE, dValue);
else
{
/*Set rotation rate*/
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_RATE, dValue));
}
}
static void DS_SetRotationMode(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter Rotation Mode (Continuous = 0 / Start-Stop = 1)\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_MODE, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_MODE, dValue);
else
{
/*Set rotation mode*/
check_status(naibrd_DS_SetRotationCtrl(cardIndex, module, channel, NAI_DS_ROTATION_MODE, dValue));
}
}
static void DS_SetRotationStartAngle(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter Rotation Start Angle [0.0 - 359.9954]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_START_ANG, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_START_ANG, dValue);
else
{
/*Set rotation start angle*/
check_status(naibrd_DS_SetAngle(cardIndex, module, channel, NAI_DS_ANGLE_SINGLE, dValue));
}
}
static void DS_SetRotationStopAngle(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter Rotation Stop Angle [0.0 - 359.9954]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_SET_ROT_STOP_ANG, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_SET_ROT_STOP_ANG, dValue);
else
{
/*Set rotation stop angle*/
check_status(naibrd_DS_SetAngle(cardIndex, module, channel, NAI_DS_ANGLE_ROTATION_STOP, dValue));
}
}
static void DS_StartRotation(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nTrigger Start Rotation[STOP = 0, GO = 1]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_INITIATE_ROTATION, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_INITIATE_ROTATION, dValue);
else
{
/*Start Rotation*/
check_status(naibrd_DS_SetRotationEnable(cardIndex, module, channel, (uint8_t)dValue));
}
}
static void DS_StopRotation(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0.0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nTrigger Stop Rotation[STOP = 0, GO = 1]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_STOP_ROTATION, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_STOP_ROTATION, dValue);
else
{
/*Stop Rotation*/
check_status(naibrd_DS_SetRotationEnable(cardIndex, module, channel, (uint8_t)dValue));
}
}
static void DS_SetPower(int32_t cardIndex, int32_t module, int32_t channel)
{
float64_t dValue = 0;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nSet Power[DISABLE = 0, ENABLE = 1]\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
dValue = atof((const char *)inputBuffer);
bQuit = checkUserInput(DS_USER_INPUT_POWER, dValue);
if (bQuit == TRUE)
printInvalidUserInputMessage(DS_USER_INPUT_POWER, dValue);
else
{
check_status(naibrd_DS_SetPowerEnable(cardIndex, module, channel, (uint8_t)dValue));
}
}
static uint32_t getUserInput()
{
uint32_t unCmdNumber = 0;
int8_t str1[80];
int8_t str2[80];
uint32_t udCommand = 0;
int32_t x;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
for (unCmdNumber = 0; unCmdNumber < DS_USER_INPUT_COUNT && DS_DemoUserInputs[unCmdNumber].cmdstr != NULL; unCmdNumber++)
{
memset(str1, 0, sizeof(str1));
memset(str2, 0, sizeof(str2));
strncpy((char*)str1, (const char*)DS_DemoUserInputs[unCmdNumber].cmdstr, inputResponseCnt);
strncpy((char*)str2, (const char*)inputBuffer, inputResponseCnt);
for (x = 0; x < inputResponseCnt; x++)
{
str1[x] = (int8_t)toupper(str1[x]);
str2[x] = (int8_t)toupper(str2[x]);
}
if (strncmp((const char*)str1, (const char*)str2, inputResponseCnt) == 0)
{
udCommand = unCmdNumber;
break;
}
}
return(udCommand);
}
static bool_t checkUserInput(uint32_t uTypeIdx, float64_t dUserInput)
{
bool_t bValidInput = FALSE;
if ((dUserInput > DS_Inputs_Limits[uTypeIdx].upperLimit) || (dUserInput < DS_Inputs_Limits[uTypeIdx].lowerLimit))
bValidInput = TRUE;
return(bValidInput);
}
static void printInvalidUserInputMessage(uint32_t uTypeIdx, float64_t dUserInput)
{
printf("\n%s: %0.4f is outside the limits[%0.4f - %0.4f]", DS_Inputs_Limits[uTypeIdx].cmdstr, dUserInput, DS_Inputs_Limits[uTypeIdx].lowerLimit, DS_Inputs_Limits[uTypeIdx].upperLimit);
}
static void showCurrentModChan(int32_t nModule, int32_t nChannel)
{
printf("\nModule :%d", nModule);
printf("\nChannel :%d", nChannel);
}