#include "SampleAppsHelper.h"
#include "rsi.h"
int main()
{
const std::string SAMPLE_APP_NAME = "Math Blocks: Calculate Acceleration from Velocity";
const int NUM_AXES = 1;
const int AXIS_INDEX = 0;
const double VELOCITY = 1.0;
const double ACCELERATION = 0.123;
int initialMathBlockCount = -1;
int exitCode = -1;
try
{
const int subtractionMathBlockIndex = initialMathBlockCount;
const int previousVelocityMathBlockIndex = initialMathBlockCount + 1;
RSIAxisAddressType INPUT_AXIS_ADDRESS_TYPE = RSIAxisAddressType::RSIAxisAddressTypeCOMMAND_VELOCITY;
controller->
AddressGet(RSIControllerAddressType::RSIControllerAddressTypeMATHBLOCK_PROCESS_VALUE, previousVelocityMathBlockIndex);
subtractionConfig.
Operation = RSIMathBlockOperation::RSIMathBlockOperationSUBTRACT;
uint64_t userBufferAddr0 = controller->
AddressGet(RSIControllerAddressType::RSIControllerAddressTypeUSER_BUFFER, 0);
previousVelocityConfig.
InputDataType0 = RSIDataType::RSIDataTypeDOUBLE;
previousVelocityConfig.
InputDataType1 = RSIDataType::RSIDataTypeDOUBLE;
previousVelocityConfig.
Operation = RSIMathBlockOperation::RSIMathBlockOperationMULTIPLY;
std::cout << "Calculated acceleration from MathBlock: " << calculatedAcceleration << std::endl;
if (std::abs(calculatedAcceleration - ACCELERATION) <= 0.000001)
{
std::cout << "The MathBlock is calculating the Axis' acceleration by subtracting previous velocity from current velocity." << std::endl;
exitCode = 0;
}
else
{
std::cerr << "Error: The calculated acceleration does not match the expected value" << std::endl;
exitCode = -1;
}
}
catch (const std::exception &ex)
{
std::cerr << ex.what() << std::endl;
exitCode = -1;
}
if (initialMathBlockCount != -1) { controller->
MathBlockCountSet(initialMathBlockCount); }
return exitCode;
}
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.
void SampleWait(uint32_t samples)
Wait for controller firmware to execute samples.
int32_t MathBlockCountGet()
Get the number of MathBlocks processing in the firmware.
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 Cleanup(MotionController *controller)
Cleanup the controller and restore the object counts to the original values.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
static void SetupController(MotionController *controller, int numAxes=0)
Setup the controller with user defined axis counts and configuration.
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...
double Double
Double precision (64-bit) floating-point.