22.3.1.2. RecurDyn Host Mode
For the synchronous simulation of control design tool and RecurDyn, following five steps are required as shown in Figure 22.45.
Communication Sequence
Make the shared memory and call the Simulink by the RecurDyn, wait the control output (2) of the Simulink.
Send the control output from the Simulink, wait the plant output (4) of the RecurDyn.
Receive plant inputs (=control output) from the shared memory.
Send plant outputs from RecurDyn.
Receive the Sensor input (=Plant output) from the shared memory.
22.3.1.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\Simulink_CoSim\.
Create a new working directory.
Copy the RecurDyn model(mouse.rdyn) and Simulink model(simouse.mdl) 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.
If the simulation stops abnormally, fix the model and try the simulation again.
22.3.1.2.2. Step II (In RecurDyn)
Step to identify general 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 General GPlant Input List dialog box appears as shown in Figure 22.49. For more information, click here.
Add a GPlant input as the name of the actuator.
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 general 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 General Plant Output List dialog box appears as shown in Figure 22.52. For more information, click here.
Add GPlant outputs as expression functions. At this dialog, the defined expression functions are as following figures.
Step to set interface information
Save the RecurDyn model in the normal fashion.
Click the GCoSim icon of the Control group in the Communicator tab. The General CoSim dialog box appears. For more information, click here.
Click Add button.
Define the name of General CoSim as GCoSim1.
Select the type of General CoSim as Simulink.
Click the PIN (…) button. The General GPlant Input List (GCoSim1) dialog box appears.
Click Add button. Automatically “Control_torque” is input. And click OK button.
Likewise Clink the POUT (…) button. The General GPlant Output List (GCoSim1) dialog box appears.
Click Add button twice. Automatically “displacement” and “velocity” are input. And Click OK button.
Click CoSim(…) button. The Simulink (GCoSim1) dialog box appears.
Select the Host Program as RecurDyn.
Export the M file to create a Plant Block after defining the names.
Click OK.
Save the RecurDyn model and terminate the RecurDyn program.
22.3.1.2.3. Step III (In MATLAB)
Step to build Simulink model with RecurDyn Plant Block
Run the MATLAB program.
Change the working directory to the directory that includes the M file and RecurDyn model.
In the MATLAB command window, enter the name of M file.
In the MATLAB command window, enter GRDHost.
And then, a new Simulink window with RecurDyn Plant Block appears.
Open the Simulink model (simouse.mdl).
Drag and drop RecurDyn Plant Block on the opened Simulink model window.
Construct the control algorithm as shown in Figure 22.62.
Save the Simulink model.
Terminate MATLAB program.
22.3.1.2.4. Step IV (In RecurDyn)
Step to set parameters for batch job of simulink
Enter the executable file name and the installation directory of the MATLAB program.
Enter the name of Simulink model that is built for the co-simulation with RecurDyn.
Enter the name of M file to run Simulink model to be used for the batch job of Simulink model and click Export.
Note
The exported data includes the simulation time of Analysis dialog box. So, check the end time before export m file.
22.3.1.2.5. Step V (In RecurDyn)
Step to do the co-simulation
Run the dynamic analysis of RecurDyn. RecurDyn automatically executes MATLAB program.
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 Plant 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 Plant Output item. Expand the displacement and velocity and double-click on each Value.