#include "helpers.h"
#include "config.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
{
initialMathBlockCount = controller->MathBlockCountGet();
const int subtractionMathBlockIndex = initialMathBlockCount;
const int previousVelocityMathBlockIndex = initialMathBlockCount + 1;
controller->MathBlockCountSet(initialMathBlockCount + 2);
Axis *axis = controller->AxisGet(AXIS_INDEX);
controller->MemoryDoubleSet(userBufferAddr0, 1.0);
controller->MathBlockConfigSet(subtractionMathBlockIndex, subtractionConfig);
controller->MathBlockConfigSet(previousVelocityMathBlockIndex, previousVelocityConfig);
controller->SampleWait(1);
controller->SampleWait(10);
double calculatedVelocityDelta = controller->MathBlockProcessValueGet(subtractionMathBlockIndex).Double;
double calculatedAcceleration = calculatedVelocityDelta * controller->SampleRateGet() * controller->SampleRateGet() / axis->
UserUnitsGet();
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); }
controller->Delete();
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,...
static MotionController * Create(CreationParameters *creationParameters)
Initialize and start the RMP EtherCAT controller.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
void ClearFaults()
Clear all faults for an Axis or MultiAxis.
void Abort()
Abort an axis.
int32_t MotionDoneWait()
Waits for a move to complete.
int32_t AmpEnableSet(bool enable, int32_t ampActiveTimeoutMilliseconds=AmpEnableTimeoutMillisecondsDefault, bool overrideRestrictedState=false)
Enable all amplifiers.
@ RSIMathBlockOperationSUBTRACT
Subtraction operation.
@ RSIMathBlockOperationMULTIPLY
Multiplication operation.
@ RSIControllerAddressTypeUSER_BUFFER
First location in User Buffer.
@ RSIControllerAddressTypeMATHBLOCK_PROCESS_VALUE
the processed value of a math block (must specify object index)
@ RSIDataTypeDOUBLE
double (64-bit floating point)
RSIAxisAddressType
Used to get firmware address used in User Limits, Recorders, etc.
@ RSIAxisAddressTypeCOMMAND_VELOCITY
Command Velocity.
void SetupController(MotionController *controller, int numAxes=0)
Setup the controller and check if the network is in the correct state for the configuration.
MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
void Cleanup(MotionController *controller)
[SetupController]
void CheckErrors(RapidCodeObject *rsiObject, const std::source_location &location=std::source_location::current())
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
void PrintHeader(std::string sampleAppName)
[NetworkShutdown]
void PrintFooter(std::string sampleAppName, int exitCode)
[PrintHeader]
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...