12#include "SampleAppsHelper.h"
18static std::vector<int> MinMaxAvg(std::vector<int> data)
24 for (
int i = 0; i < data.size(); i++)
37 int avg = sum / data.size();
38 return {min, max, avg};
43 const std::string SAMPLE_APP_NAME =
"Utilities: Record Performance";
49 const int RECORD_PERIOD_SAMPLES = 1;
50 const int RECORD_TIME = 1000;
67 bool networkTimingEnabled =
false;
68 if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateOPERATIONAL)
70 std::cout <<
"Network is not operational. Only Firmware Timing Deltas will be recorded." << std::endl;
77 networkTimingEnabled =
true;
98 if (networkTimingEnabled)
106 controller->
OS->
Sleep(RECORD_TIME);
110 std::cout <<
"There are " << recordCount <<
" records available." << std::endl;
113 std::vector<int> firmawareTimingDeltas(recordCount);
114 std::vector<int> networkTimingDeltas(recordCount);
115 std::vector<int> networkTimingReceiveDeltas(recordCount);
117 for (
int i = 0; i < recordCount; i++)
122 if (networkTimingEnabled)
130 std::vector<int> firmwareTimingStats = MinMaxAvg(firmawareTimingDeltas);
131 std::cout <<
"Firmware Timing Deltas (us): ";
132 std::cout <<
" Min = " << std::setw(4) << firmwareTimingStats[0];
133 std::cout <<
" Max = " << std::setw(4) << firmwareTimingStats[1];
134 std::cout <<
" Avg = " << std::setw(4) << firmwareTimingStats[2] << std::endl;
136 if (networkTimingEnabled)
138 std::vector<int> networkTimingStats = MinMaxAvg(networkTimingDeltas);
139 std::cout <<
"Network Timing Deltas (us): ";
140 std::cout <<
" Min = " << std::setw(4) << networkTimingStats[0];
141 std::cout <<
" Max = " << std::setw(4) << networkTimingStats[1];
142 std::cout <<
" Avg = " << std::setw(4) << networkTimingStats[2] << std::endl;
144 std::vector<int> networkTimingReceiveStats = MinMaxAvg(networkTimingReceiveDeltas);
145 std::cout <<
"Network Timing Receive Deltas (us):";
146 std::cout <<
" Min = " << std::setw(4) << networkTimingReceiveStats[0];
147 std::cout <<
" Max = " << std::setw(4) << networkTimingReceiveStats[1];
148 std::cout <<
" Avg = " << std::setw(4) << networkTimingReceiveStats[2] << std::endl;
156 catch (
const std::exception &ex)
158 std::cerr << ex.what() << std::endl;
int32_t RecorderRecordCountGet()
Get the number of records that are stored and ready for reading.
void RecorderStart()
Start recording data.
void RecorderCircularBufferSet(bool enable)
Configure recorder as circular buffer (or not).
RSINetworkState NetworkStateGet()
void RecorderRecordDataRetrieve()
Retrieve one record of recorded data.
void RecorderDataCountSet(int32_t count)
Set the number of data values to be recorded.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
static MotionController * Create()
Initialize and start the RMP EtherCAT controller.
int32_t RecorderRecordDataValueGet(int32_t index)
Get one value from a retrieved record.
void RecorderStop()
Stop recording data.
void Delete(void)
Delete the MotionController and all its objects.
void RecorderReset()
Reset the recorder.
int32_t RecorderCountGet()
Get the number of Recorder available in the firmware.
void RecorderDataAddressSet(int32_t index, uint64_t address)
Setup the addresses to be recorded.
void RecorderPeriodSet(uint32_t samples)
Set the number of samples between records.
void RecorderCountSet(int32_t recorderCount)
Set the number of processed Recorders in the controller.
bool RecorderEnabledGet()
Determine if the recorder is recording.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
RapidCodeOS * OS
Provides access to operating system (Windows) features.
void NetworkTimingEnableSet(bool enable)
Enable or disable the firmware to start timing the network packets.
void Sleep(int32_t milliseconds)
Put the current thread to sleep.
static void PrintFooter(std::string sampleAppName, int exitCode)
Print a message to indicate the sample app has finished and if it was successful or not.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PrintHeader(std::string sampleAppName)
Print a start message to indicate that the sample app has started.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
CreationParameters for MotionController::Create.