Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Cheng Fang
Posts: 8
Joined: Wed Jul 22, 2015 6:43 am

Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Cheng Fang » Sun May 17, 2020 1:08 pm

Hi there:

I and my friends had tried to implement forward dynamic simulations of robots (e.g., a manipulator with a number of joints) in OpenSim 3.3 by using actuators and controllers for all the joints. We found that implementing such a robotic simulation (say, the robot is controlled by PID controllers to track predefined joint trajectories) in OpenSim 3.3 is somehow difficult.

The main issue with implementing classical PID controls was that the integrator of OpenSim usually goes back and forth in the course (at least in OpenSim 3.3), in the sense that it tries to solve the problem but if it realizes that the initially computed solution does not respect some constraints, it goes back in time and tries to compute another solution by changing something else, like, for example, the time step or other parameters. This, of course, invalidates every memory-based state in every controller or algorithm we can develop if they are not included in the OpenSim model state.

I was wondering if this issue was perceived and solved (or improved) in the latest OpenSim 4.1, which potentially enables proper dynamic simulations of robots and serves as an alternative robot simulator?

Look forward to any comments and thank you!

Best regards,
Cheng

Tags:

User avatar
Michael Sherman
Posts: 807
Joined: Fri Apr 01, 2005 6:05 pm

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Michael Sherman » Sun May 17, 2020 4:54 pm

Trial computations are a feature of all error-controlled integrators and have nothing to do with whether you are doing biomechanical or robot simulation. Many robot simulations are done with error control -- the problem you have is that you have not exposed all state to OpenSim so that it can be managed successfully (you have hidden state in your controller, apparently).

You could run OpenSim using a fixed-step integration method so that time moves only forward. However, that would preclude using error controlled methods for your robot. Better would be to improve your controller so that it can work properly either way.

Regards,
Sherm

User avatar
Cheng Fang
Posts: 8
Joined: Wed Jul 22, 2015 6:43 am

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Cheng Fang » Wed May 27, 2020 1:59 am

Hi Sherm:

Thank you very much for your insightful comments! and sorry for my late reply.

I completely agree with you that we hid some states of our controllers from OpenSim, and the reasonable solution should be trying to augment OpenSim states to include all the states of our controller (e.g., a PID controller). However, I am not sure and a bit worried about that modifying and augmenting OpenSim states might not be an easy task. Did you have any experience on that or did you have any example codes which I can refer to ?

Hope to hear from you again and many thanks!

Best regards,
Cheng

User avatar
Michael Sherman
Posts: 807
Joined: Fri Apr 01, 2005 6:05 pm

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Michael Sherman » Wed May 27, 2020 9:33 am

Hi, Cheng. I am not an experienced OpenSim user but I believe it is straightforward and common for people to add extra states in OpenSim models. I am sure an OpenSim expert can point you in the right direction -- I suspect there are examples or tutorial instructions for that.

I can say for certain that the underlying infrastructure in Simbody does support that as a typical use case.

Regards,
Sherm

User avatar
Cheng Fang
Posts: 8
Joined: Wed Jul 22, 2015 6:43 am

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Cheng Fang » Thu May 28, 2020 5:35 am

Hi Sherm:

Thanks for your reply!

We had some problems when we attempted to expose the integral of the error and its derivative in a PID controller to the model states in OpenSim 3.3, but have not checked the same issue in OpenSim 4.1 yet.

Can you name a couple of OpenSim experts if you happen to know any, in case I still get stuck in OpenSim 4.1 ?

Many thanks!

Best,
Cheng

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Ayman Habib » Thu May 28, 2020 9:07 am

Hi Cheng,

OpenSim distribution includes ExampleMuscle folder under <ResourceFolder>/Code/CPP that demonstrates how to add state variables, and state cache entries to store whatever quantities you need to maintain along with the state.

Typically the <ResourceFolder> is located under your Documents/OpenSim/${version}/

Hope this helps, but let us know if you continue to have questions.
-Ayman

User avatar
Michael Sherman
Posts: 807
Joined: Fri Apr 01, 2005 6:05 pm

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Michael Sherman » Thu May 28, 2020 9:23 am

Experts, sure -- Ayman Habib, for example!

User avatar
Cheng Fang
Posts: 8
Joined: Wed Jul 22, 2015 6:43 am

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Cheng Fang » Wed Jul 01, 2020 9:15 am

aymanh wrote:
Thu May 28, 2020 9:07 am
Hi Cheng,

OpenSim distribution includes ExampleMuscle folder under <ResourceFolder>/Code/CPP that demonstrates how to add state variables, and state cache entries to store whatever quantities you need to maintain along with the state.

Typically the <ResourceFolder> is located under your Documents/OpenSim/${version}/

Hope this helps, but let us know if you continue to have questions.
-Ayman
Hi Ayman:

Thanks for your reply and sorry for my late thanks since I was trapped with some teaching activities before. I will now look into the Muscle Example to see if my problem can be solved. I may get back to you for more questions :)

best regards,
Cheng

User avatar
Cheng Fang
Posts: 8
Joined: Wed Jul 22, 2015 6:43 am

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Cheng Fang » Wed Jul 01, 2020 9:17 am

sherm wrote:
Thu May 28, 2020 9:23 am
Experts, sure -- Ayman Habib, for example!
Thanks, Michael !

Best,
Cheng

User avatar
Cheng Fang
Posts: 8
Joined: Wed Jul 22, 2015 6:43 am

Re: Regarding the possibility of forward dynamic simulations of robots in OpenSim 4.1

Post by Cheng Fang » Tue Jul 07, 2020 10:18 am

aymanh wrote:
Thu May 28, 2020 9:07 am
Hi Cheng,

OpenSim distribution includes ExampleMuscle folder under <ResourceFolder>/Code/CPP that demonstrates how to add state variables, and state cache entries to store whatever quantities you need to maintain along with the state.

Typically the <ResourceFolder> is located under your Documents/OpenSim/${version}/

Hope this helps, but let us know if you continue to have questions.
-Ayman
Hi Ayman:

Now I encountered a couple of specific problems after looking into the Muscle Example you showed me.

I modeled a 7-DOF robotic manipulator in OpenSim, comprised of 7 PinJoints being actuated by CoordinateActuator type actuators. The objective is to implement a controller that maintains the robotic arm at a specified joint posture (q_des), and a bigger objective is to enable simulations of physical human-robot interactions in OpenSim.

For this, the Controller class is extended and the desired actuation torque is computed in the computeControls() method as "tau_des = Kp * (q_des - q) - Kd * qdot + g" with values (q, qdot) extracted from the state variables.

This torque (tau_des) and its temporal derivate (tau_des_dot) must be constrained (saturated) in the control loop (due to the physical limits of real robot actuators), which is difficult to implement due to time being able to go back and forth.

I am slightly confused on how to use OpenSim's API to add the state variables, update their values and compute the derivaties. In my case, the desired torque (tau_des) and its derivative (tau_des_dot) are the desired state variables to be managed by OpenSim.

Looking at the FatigableMuscle.cpp example, from my understanding, the extendSetPropertiesFromState() must be overridden to specify/update the values of the custom state variables at each control loop, i.e., computing tau_des at a given state in my case.

Then, the function computeStateVariableDerivatives() must be overridden to compute the derivatives, e.g. tau_des_dot, which is expected to be calculated by the equation "(tau_des(s) - tau_des(s')) / (t(s) - t(s'))", where s and s' are the current state and its preceding state. How can s' be accessed or is there a different way of calculating tau_des_dot?

-

Another two questions:

1) is there a more conventinoal or convenient way to enforce joint position, velocity and torque limits to an OpenSim model (a robot model in our case)?

2) In robotics, to actuate a real robot practically and guarantee the stability of the whole physical system, we usually command the control inputs (joint torques) at a high and constant frequency, say 1kHz, which means the control cycle or time step size is 1ms. But I realized that, in Biomechanics, accuracy in simulations is more important and error-controlled integrators are used employed which results in variable time steps. I was thinking if it is also possible to enforce the time in OpenSim to only move forward with a fixed step? and how?

Look forward to your help and thanks a lot in advance!

Best regards,
Cheng

POST REPLY