APIs, concepts, guides, and more
Memory.cpp
1
18#include "rsi.h" // Import our RapidCode Library.
19#include "SampleAppsHelper.h" // Import our SampleApp helper functions.
20#include "SampleApps.h"
21
22using namespace RSI::RapidCode; // Import the RapidCode namespace
23
25int Memory::Run()
26{
27 /* CONSTANTS */
28 // *NOTICE* The following constants must be configured before attempting to run with hardware.
29
30 // Axis configuration parameters
31 const int AXIS_COUNT = 1; // Specify how many axes we will be using in this sample.
32 const int AXIS_NUMBER = 0; // Specify which axis/motor we will be controlling.
33
34 // To run with hardware, set the USE_HARDWARE flag to true AFTER you have configured the parameters above and taken proper safety precautions.
35 USE_HARDWARE = false;
36
37 /* SAMPLE APP BODY*/
38
39 Axis* axis;
40 uint64_t addr;
41
42 // Initialize MotionController class. (PCI board)
45
46 // Setup the controller for the appropriate hardware configuration.
47 if (USE_HARDWARE)
48 {
50 }
51 else
52 {
53 SampleAppsHelper::SetupControllerForPhantoms(controller, AXIS_COUNT, { AXIS_NUMBER });
54 }
55
56 // initialize Axis (0)
57 axis = controller->AxisGet(AXIS_NUMBER);
59
60 try
61 {
62 // get a controller host address for axis memory
64 printf("Axis Host address is 0x%llx Firmware Address is 0x%x\n", addr, controller->FirmwareAddressGet(addr));
65 printf("Value is %lf\n", controller->MemoryDoubleGet(addr)); // ACTUAL_POSITION is a 64-bit double
66 }
67 catch (RsiError const& err)
68 {
69 printf("\n%s\n", err.text);
70 return -1;
71 }
72
73 controller->Delete(); // Delete the controller as the program exits to ensure memory is deallocated in the correct order.
74 return 0;
75}
76
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.
static MotionController * CreateFromSoftware()
Initialize and start the RMP EtherCAT controller.
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
@ RSIAxisAddressTypeACTUAL_POSITION
Actual Position.
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.