22.3.2.2. RecurDyn Host Mode
22.3.2.2.1. Step I (In RecurDyn)
Step to open the RecurDyn model
The model is provided in the RecurDyn installation directory <Install Dir>\Help\Examples\GCoSim\External\CPP\.
Create a new working directory.
Copy the RecurDyn model (mouse.rdyn) from the directory paste to the newly created working directory.
Run RecurDyn.
Open the RecurDyn model. And then, the mouse model appears in the working window.
Step to verify the mechanical system model
Prior to applying a control system to this model, make sure that the mouse model runs without any errors.
Select Dynamic/Kinematic icon of the Simulation group in the Analysis tab.
Enter End time and Step.
Click Simulate.
Save the RecurDyn model and terminate the RecurDyn program.
22.3.2.2.2. Step II (In RecurDyn)
Step to identify GPlant inputs
The input of interest is the single rotational axial force is applied to the wheel Revolute Joint to move the mouse.
Click the GPlant_Input icon of the Control group in the Communicator tab. The GPlant Input List dialog box appears as shown in Figure 22.86.
Add a GPlant input as the name of the actuator. For more information, click here.
Add an expression function as a following figure.
Open the dialog box of Rotational Axial force by double clicking RotationalAxial1 in the Database window. And then input the expression function defined in the upper step.
Step to identify GPlant outputs
The output of interest is the displacement and velocity between the ball and the Mouse body pointer. This distance is in the X direction.
Click the. GPlant_Output icon of the Control group in the Communicator tab. The GPlant Output List dialog box appears as shown in Figure 22.89.
Add GPlant outputs as expression functions. For more information, click here. At this dialog, the defined expression functions are as following figures.
Close the RecurDyn Program after save the RecurDyn model.
22.3.2.2.3. Step III (In User-defined Program)
Step to design control system
Run the Microsoft Visual Studio.
Create a new project from the File Menu.
Open the New Project window as shown.
Select Win32 Console Application”
Define the Location as new working directory.
Select the option as Empty project of the Console Application.
The sample test code is provided in the RecurDyn installation directory <Install dir>\Help\Examples\GCoSim\External\CPP\.
Copy the sample test code(GCoSim_RDHost.cpp) from the directory paste to the working directory.
The library and DLL files are provided in the RecurDyn installation directory <Install dir>\Toolkits\Controls\GCoSim\External\.
Copy the library file(RDGCoSim.lib/RDGCS_HostAPI.lib) and DLL file(RDGCoSim.dll/RDGCS_HostAPI.dll) from the directory paste to the working directory.
Note
If you want to see functions provided by the library file(RDGCoSim.lib/RDGCS_HostAPI.lib) and DLL file(RDGCoSim.dll/RDGCS_HostAPI.dll) click here.
Add an example source file (GCoSim_RDHost.cpp) from a working directory.
Change the solution platform to x64.
Link the RDGCoSim.lib/RDGCS_HostAPI.lib in your project. (This file contains the interface functions such as a CreateRecurDynInterface, CommunicateRecurDyn, FreeCosimMemory functions)
Implement your own codes in this source file (GCoSim_RDHost.cpp).
Create your EXE file by using the Rebuild Solution option of Visual Studio.
=============== Interface Function ==========================
- CreateRecurDynInterface:
char* chInterface
int iNPin
int iNPout
int* seqIf
int* errorcode
This function must be called only one before interfacing.
Parameter Name |
Unit |
IO type |
Type |
Description |
---|---|---|---|---|
chInterface |
[-] |
Input |
char* |
The unique Name for Interface to each other. |
iNPin |
[-] |
Input |
int |
The Number of Plant Input. |
iNPout |
[-] |
Input |
int |
The Number of Plant Output. |
seqIf |
[-] |
Output |
int |
The ID (sequence) of created interface. |
errorcode |
[-] |
Output |
int |
0: no error 1: The model can’t be simulated. 2: RecurDyn can’t be executed. |
- CommunicateRecurDyn:
int seqIf
int count
double sim_time
int iNPin
int iNPout
double* dPIN
double* dPOUT
double* rd_time
int* errorcode
This function must be called once at interface time step.
Parameter Name |
Unit |
IO type |
Type |
Description |
---|---|---|---|---|
seqIf |
[-] |
Input |
int |
The ID (sequence) of created interface. |
count |
[-] |
Input |
int |
The count of Interface |
sim_time |
[-] |
Input |
double |
Is the simulation time |
iNPin |
[-] |
Input |
int |
Is the the number of plant input |
iNPout |
[-] |
Input |
int |
Is the number of plant output |
dPIN |
[-] |
Input |
double |
Is the values of plant input |
dPOUT |
[-] |
Output |
double |
Is the values of plant output |
rd_time |
[-] |
Output |
double |
Is the RecurDyn simulation time |
errorcode |
[-] |
Output |
int |
0: no error 1: The model is abnormally stopped 2: The RecurDyn don’t respond. 3: Interface time don’t match. |
- FreeCosimMemory:
int seqIf : The ID (sequence) of created interface, input type.
This function must be called only one after interfacing.
22.3.2.2.4. Step IV (In RecurDyn)
Step to build the co-simulation environment
Copy the built EXE and library and DLL files to the working directory of the RecurDyn model.
Note
The built EXE and library and DLL files should be in the same folder with the RecurDyn model.
Step to do the co-simulation
Open the mouse.rdyn.
Click the General icon of the Control group in the Communicator tab. The CoSim dialog box appears.
Change the Host Program in External to RecurDyn.
Import the EXE file(RDGCS_HostAPI.exe).
Edit Sampling Period (Control Time Step).
Click OK.
Run Simulation.
22.3.2.2.5. Step V (In RecurDyn)
Step to see the Animation Result
In RecurDyn, play the animation.
Step to see the Plot Result
To plot the output data, click the Result icon of Plot group in Analysis tab.
Expand the GPlant Input item in the database window on the right side. Expand the Control_torque. Double-click on Value in the section and adjust the label and axes to get the plot below.
Expand the GPlant Output item. Expand the displacement and velocity and double-click on each Value.