APIs, concepts, guides, and more
Memory.cpp
#include "rsi.h" // Import our RapidCode Library.
#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
#include "SampleApps.h"
using namespace RSI::RapidCode; // Import the RapidCode namespace
int Memory::Run()
{
/* CONSTANTS */
// *NOTICE* The following constants must be configured before attempting to run with hardware.
// Axis configuration parameters
const int AXIS_COUNT = 1; // Specify how many axes we will be using in this sample.
const int AXIS_NUMBER = 0; // Specify which axis/motor we will be controlling.
// To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
USE_HARDWARE = false;
/* SAMPLE APP BODY*/
Axis* axis;
uint64_t addr;
// Initialize MotionController class. (PCI board)
MotionController* controller = MotionController::CreateFromSoftware();
// Setup the controller for the appropriate hardware configuration.
if (USE_HARDWARE)
{
}
else
{
SampleAppsHelper::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_NUMBER });
}
// initialize Axis (0)
axis = controller->AxisGet(AXIS_NUMBER);
try
{
// get a controller host address for axis memory
addr = axis->AddressGet(RSIAxisAddressType::RSIAxisAddressTypeACTUAL_POSITION);
printf("Axis Host address is 0x%llx Firmware Address is 0x%x\n", addr, controller->FirmwareAddressGet(addr));
printf("Value is %lf\n", controller->MemoryDoubleGet(addr)); // ACTUAL_POSITION is a 64-bit double
}
catch (RsiError const& err)
{
printf("\n%s\n", err.text);
return -1;
}
controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
return 0;
}
uint64_t AddressGet(RSIAxisAddressType addressType)
Get the an address for some location on the Axis.
Represents a single axis of motion control. This class provides an interface for commanding motion,...
Definition rsi.h:5643
Axis * AxisGet(int32_t axisNumber)
AxisGet returns a pointer to an Axis object and initializes its internals.
uint32_t FirmwareAddressGet(uint64_t hostAddress)
Convert a host controller address to a firmware address.
void Delete(void)
Delete the MotionController and all its objects.
double MemoryDoubleGet(uint64_t address)
Read a 64-bit double value from controller memory.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
Definition rsi.h:796
Represents the error details thrown as an exception by all RapidCode classes. This class contains an ...
Definition rsi.h:107
static void SetupControllerForHardware(MotionController *controller)
Sets up the controller for hardware use by resetting it and starting the network.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void SetupControllerForPhantoms(MotionController *controller, int axisCount, std::vector< int > axisNums)
Sets up the controller for phantom axes, including configuring specified axes as phantom.