Some problems with tugOfWar example

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Some problems with tugOfWar example

Post by Sina Porsa » Tue Dec 20, 2011 7:11 pm

Hi,
I am trying to compile the tugOfWar example in the "OpenSim Developers Guide" step by step. I want to modify step 15 (which uses some functions to make the muscle control history at page 34) and replace the LinearFunction with PiecewiseLinearFunction. So I replaced this piece of code:

Code: Select all

PrescribedController *muscleController = new PrescribedController();
muscleController->setActuators(osimModel.updActuators());
Array<double> slopeAndIntercept1(0.0, 2); // array of 2 doubles
Array<double> slopeAndIntercept2(0.0, 2);
slopeAndIntercept1[0] = -1.0/(finalTime-initialTime);
slopeAndIntercept1[1] = 1.0;
slopeAndIntercept2[0] = 1.0/(finalTime-initialTime);
slopeAndIntercept2[1] = 0.05;
muscleController->prescribeControlForActuator("muscle1", new LinearFunction(slopeAndIntercept1));
muscleController->prescribeControlForActuator("muscle2", new LinearFunction(slopeAndIntercept2));
with this:

Code: Select all

PrescribedController *muscleController = new PrescribedController();
muscleController->setActuators(osimModel.updActuators());
double time[3] = {0, finalTime/2, finalTime};
double value1[3] = {0.5, 1.0, 0.5};
double value2[3] = {0.25, 0.5, 0.75};
muscleController->prescribeControlForActuator("muscle1", new PiecewiseLinearFunction(3,time,value1));
muscleController->prescribeControlForActuator("muscle2", new PiecewiseLinearFunction(3,time,value2));
The code does not return any errors and OpenSim integrates the equations from initial time to the final time. But the activation of muscles is not a piece wise linear function.
It would be great if someone could help me to solve this issue.
Regards,
Sina

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

Re: Some problems with tugOfWar example

Post by Ayman Habib » Tue Jan 03, 2012 12:34 pm

Hi Sina,

Can you please explain why you think your controller doesn't work?

Thanks,
-Ayman

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: Some problems with tugOfWar example

Post by Sina Porsa » Tue Jan 03, 2012 5:00 pm

Hi Ayman,
according to the code, I expect piece-wise linear excitation/activation for muscles. I have attached the activation plots which is not linear. The activatoin initiates at its initial value and decreases by time.
Cheers,
Sina.
Attachments
TugOfWar.png

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: Some problems with tugOfWar example

Post by Sina Porsa » Mon Feb 13, 2012 8:56 pm

Hi Ayman,
I do still have problem with the tugOfWar example.
In the "developers guide - section 2.16" we define two linear functions for each of the muscles. I compiled and ran the code and loaded the results in the GUI. I expected linear activation in the muscles, but as you can see in the attached file, the activations are not linear. Here is my c++ code:

Code: Select all

// Create a prescribed controller that simply applies controls as function of time
		PrescribedController *muscleController = new PrescribedController();
		muscleController->setActuators(osimModel.updActuators());
		// Define linear functions for the control values for the two muscles
		Array<double> slopeAndIntercept1(0.0, 2); // array of 2 doubles
		Array<double> slopeAndIntercept2(0.0, 2);
		// muscle1 control has slope of -1 starting 1 at t = 0
		slopeAndIntercept1[0] = -1.0/(finalTime-initialTime);
		slopeAndIntercept1[1] = 1.0;
		// muscle2 control has slope of 1 starting 0.05 at t = 0
		slopeAndIntercept2[0] = 1.0/(finalTime-initialTime);
		slopeAndIntercept2[1] = 0.5;
		// Set the indiviudal muscle control functions for the prescribed muscle controller
		muscleController->prescribeControlForActuator("muscle1", new LinearFunction(slopeAndIntercept1));
		muscleController->prescribeControlForActuator("muscle2", new LinearFunction(slopeAndIntercept2));
		// Define the initial states for the two muscles
		// Initial activation correspond to control at time=0
		muscle1->setDefaultActivation(slopeAndIntercept1[1]);
		muscle2->setDefaultActivation(slopeAndIntercept2[1]);
Attachments
TugOfWar1_CreateModel.cpp
(9.13 KiB) Downloaded 29 times
TugOfWar.png
The muscle activations which is supposed to be linear.

User avatar
Romain LEBERRE
Posts: 12
Joined: Fri Feb 24, 2012 11:47 am

Re: Some problems with tugOfWar example

Post by Romain LEBERRE » Thu Apr 19, 2012 12:32 pm

Hi,
has this issue been solved? I am encountering the same problem. Activations decrease non linearly from their initial value (initial activation) to zero as shown in the previous post. Activations/time plots are the same with or without the setting of the individual muscle control functions for the prescribed muscle control :

//// Set the indiviudal muscle control functions for the prescribed muscle controller
muscleController->prescribeControlForActuator("muscle1", new LinearFunction(slopeAndIntercept1));
muscleController->prescribeControlForActuator("muscle2", new LinearFunction(slopeAndIntercept2));

as if these lines do not impact muscles control.

Thank you.
Romain

User avatar
Ajay Seth
Posts: 136
Joined: Thu Mar 15, 2007 10:39 am

Re: Some problems with tugOfWar example

Post by Ajay Seth » Mon Apr 23, 2012 12:38 pm

Is the problem that the activations are nonlinear? In general, activation is a state of the muscle and it governed by the excitation via a first order differential eqn.
If you are using the Thelen2003Muscle, activation is definitely a state.

If the problem is that the activation does not change with expected changes to the excitation (control) according to your prescribed function, then there is something we can investigate.

Please let us know.

User avatar
Ajay Seth
Posts: 136
Joined: Thu Mar 15, 2007 10:39 am

Re: Some problems with tugOfWar example

Post by Ajay Seth » Mon Apr 23, 2012 3:33 pm

There is a line missing in the example. The controller was not being added to the model.

Code: Select all

// Add the muscle controller to the model
osimModel.addController(muscleController);
Add this after creating the controller but before initSystem().

Thank you for finding this oversight.
Please let us know if this now works for you.

User avatar
Romain LEBERRE
Posts: 12
Joined: Fri Feb 24, 2012 11:47 am

Re: Some problems with tugOfWar example

Post by Romain LEBERRE » Wed Apr 25, 2012 4:35 am

It works now. Thank you

User avatar
Sina Porsa
Posts: 99
Joined: Thu Feb 03, 2011 7:21 pm

Re: Some problems with tugOfWar example

Post by Sina Porsa » Wed Apr 25, 2012 8:33 pm

Hi Ajay and Romain, sorry for my late reply.
Thanks, it works now. The problem was the missed line as Ajay mentioned.
I just understood that the same line is missing in the API example file in opensim directory. (c:\OpenSim2.4.0\sdk\APIExamples\ExampleMain\TugOfWar_Complete.cpp)
It would be great if you could solve this problem.
Cheers.
Sina

POST REPLY