10#include "SampleAppsHelper.h"
17 const std::string SAMPLE_APP_NAME =
"Math Blocks: Calculate Acceleration from Velocity";
24 const double VELOCITY = 1.0;
25 const double ACCELERATION = 0.123;
59 const int PREVIOUS_VELOCITY_MATHBLOCK_INDEX = SUBTRACTION_MATHBLOCK_INDEX + 1;
63 RSIAxisAddressType INPUT_AXIS_ADDRESS_TYPE = RSIAxisAddressType::RSIAxisAddressTypeCOMMAND_VELOCITY;
72 controller->
AddressGet(RSIControllerAddressType::RSIControllerAddressTypeMATHBLOCK_PROCESS_VALUE, PREVIOUS_VELOCITY_MATHBLOCK_INDEX);
76 subtractionConfig.
Operation = RSIMathBlockOperation::RSIMathBlockOperationSUBTRACT;
79 uint64_t userBufferAddr0 = controller->
AddressGet(RSIControllerAddressType::RSIControllerAddressTypeUSER_BUFFER, 0);
85 previousVelocityConfig.
InputDataType0 = RSIDataType::RSIDataTypeDOUBLE;
87 previousVelocityConfig.
InputDataType1 = RSIDataType::RSIDataTypeDOUBLE;
88 previousVelocityConfig.
ProcessDataType = RSIDataType::RSIDataTypeDOUBLE;
89 previousVelocityConfig.
Operation = RSIMathBlockOperation::RSIMathBlockOperationMULTIPLY;
93 controller->
MathBlockConfigSet(PREVIOUS_VELOCITY_MATHBLOCK_INDEX, previousVelocityConfig);
117 std::cout <<
"Calculated acceleration from MathBlock: " << calculatedAcceleration << std::endl;
120 if (std::abs(calculatedAcceleration - ACCELERATION) <= 0.000001)
122 std::cout <<
"The MathBlock is calculating the Axis' acceleration by subtracting previous velocity from current velocity." << std::endl;
127 std::cerr <<
"Error: The calculated acceleration does not match the expected value" << std::endl;
131 catch (
const std::exception &ex)
133 std::cerr << ex.what() << std::endl;
uint64_t AddressGet(RSIAxisAddressType addressType)
Get the an address for some location on the Axis.
double UserUnitsGet()
Get the number of counts per User Unit.
void MoveVelocity(double velocity)
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
void MathBlockCountSet(int32_t mathBlockCount)
Set the number of processed MathBlocks in the MotionController.
void MemoryDoubleSet(uint64_t address, double dataDouble)
Write a 64-bit double value to controller memory.
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.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
void Delete(void)
Delete the MotionController and all its objects.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
MathBlockConfig MathBlockConfigGet(int32_t mathBlockNumber)
Get a MathBlock configuration.
FirmwareValue MathBlockProcessValueGet(int32_t mathBlockNumber)
Get a MathBlock process value.
void MathBlockConfigSet(int32_t mathBlockNumber, MathBlockConfig &config)
Set a MathBlock configuration.
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void AmpEnableSet(bool enable)
Enable all amplifiers.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
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 void SetupController(MotionController *controller)
Setup the controller with user defined axis counts and configuration.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
CreationParameters for MotionController::Create.
RSIDataType ProcessDataType
Data type for processing.
MathBlock configuration structure.
uint64_t InputAddress0
Host memory address for Input0. Represents the left-hand side operand in math operations.
RSIDataType InputDataType0
Data type for Input0. This is the data type of the left-hand side operand in math operations.
uint64_t InputAddress1
Host memory address for Input1. Represents the right-hand side operand in math operations.
RSIDataType InputDataType1
Data type for Input1. This is the data type of the right-hand side operand in math operations.
RSIMathBlockOperation Operation
Math operation to be performed. (+, -, *, /, etc) use RSIMathBlockOperationNONE to disable a MathBloc...
static constexpr int AXIS_X_INDEX
Index of the first axis to use in the sample apps.
static constexpr int MATH_BLOCK_COUNT
Number of math block objects to configure on the controller.
double Double
Double precision (64-bit) floating-point.