Prescribed controller during CMC

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Takashi Yoshida
Posts: 3
Joined: Mon Nov 13, 2017 2:20 am

Prescribed controller during CMC

Post by Takashi Yoshida » Mon Dec 14, 2020 3:13 pm

I am trying to use a prescribed controller in a CMC simulation. To this end, I have added a coordinate actuator as well as its controller (prescribed controller) to my model.

The coordinate actuator is added under <ForceSet> as follows:

<CoordinateActuator name="act_r">
<isDisabled>false</isDisabled>
<min_control>-Inf</min_control>
<max_control>Inf</max_control>
<coordinate>ankle_angle_r</coordinate>
<optimal_force>1</optimal_force>
</CoordinateActuator>

The controller is added under <ControllerSet> as follows:

<PrescribedController name="ctr_r">
<isDisabled>false</isDisabled>
<actuator_list>act_r</actuator_list>
<FunctionSet name="ControlFunctions">
<objects/>
<groups />
</FunctionSet>
<controls_file> C:\control.sto </controls_file>
<interpolation_method>1</interpolation_method>
</PrescribedController>

<controls_file> contains two columns: time and a time series, the latter of which has the heading "act_r".

For <desired_kinematics_file>, I am using an output from RRA. The time window of <controls_file> begins before and ends after that of <desired_kinematics_file>. The sampling frequency of <controls_file> is 1000 Hz, and the sampling frequency of <desired_kinematics_file> is approximately 1000 Hz.

When the model is loaded, <FunctionSet> that is generated from the <controls_file> seems to be correct.

However, when the CMC stimulation is completed, the resultant control of the coordinate actuator looks nothing like the time series in <controls_file>.

Please help.

Tags:

User avatar
Carmichael Ong
Posts: 401
Joined: Fri Feb 24, 2012 11:50 am

Re: Prescribed controller during CMC

Post by Carmichael Ong » Wed Dec 16, 2020 3:17 pm

I've also had some trouble getting a PrescribedController to work with CMC. I've worked around this before by removing the PrescribedController, keeping hte actuators added, and using the ControlConstraints file with CMC (you can specify the min and max values to be the exact value you want).

User avatar
Takashi Yoshida
Posts: 3
Joined: Mon Nov 13, 2017 2:20 am

Re: Prescribed controller during CMC

Post by Takashi Yoshida » Mon Mar 08, 2021 4:10 am

Hi Carmichael,

Thank you for your reply.

Were you ever able to prescribe an external moment to a specific joint during CMC (i.e. the moment values are predetermined as a function of time)?

I think your suggested solution does not enable that.

User avatar
Carmichael Ong
Posts: 401
Joined: Fri Feb 24, 2012 11:50 am

Re: Prescribed controller during CMC

Post by Carmichael Ong » Mon Mar 08, 2021 11:47 am

Yes, using the ControlConstraints file worked for me. A short snippet of a example XML that goes into the ControlConstraints file (if you have an actuator called "act_r" in your model, note how the values are the same in both min_nodes and max_nodes):

Code: Select all

			<ControlLinear name="act_r.excitation">
				<is_model_control>true</is_model_control>
				<extrapolate>true</extrapolate>
				<default_min>0.02</default_min>
				<default_max>1</default_max>
				<filter_on>false</filter_on>
				<use_steps>false</use_steps>
				<x_nodes />
				<min_nodes>
					<ControlLinearNode>
						<t>0</t>
						<value>0.1</value>
					</ControlLinearNode>
					<ControlLinearNode>
						<t>0.1</t>
						<value>-0.1</value>
					</ControlLinearNode>
				</min_nodes>
				<max_nodes>
					<ControlLinearNode>
						<t>0</t>
						<value>0.1</value>
					</ControlLinearNode>
					<ControlLinearNode>
						<t>0.1</t>
						<value>-0.1</value>
					</ControlLinearNode>
				</max_nodes>
				<kp>100</kp>
				<kv>20</kv>
			</ControlLinear>
The number of nodes can be as many as you need. If you have a lot of points, you could automate the process by using some XML writers from Matlab or Python. You could also use the Matlab/Python OpenSim API to automate this as well. Example Python code (note that everything is not defined, you will have to supply some of the inputs)

Code: Select all

    cs = osim.ControlSet(input_constraints_file) #input_constraints_file is the constraints file on which to build
    cl_r = osim.ControlLinear()
    cl_l = osim.ControlLinear()
    cl_r.setName('act_r.excitation')
    
    for time, right_torque in zip(time_array, right_torque_array):
        cl_r.setControlValueMin(time, right_torque)
        cl_r.setControlValueMax(time, right_torque)
        
    cs.cloneAndAppend(cl_r)

User avatar
Carmichael Ong
Posts: 401
Joined: Fri Feb 24, 2012 11:50 am

Re: Prescribed controller during CMC

Post by Carmichael Ong » Mon Mar 08, 2021 3:22 pm

If your controls are in a .sto (Storage) file, you can get the GUI to generate all of the nodes as well. Here's an example with the gait10dof18 model that we distribute with OpenSim

1. Go to the gait10dof18musc folder
2. Load the gait10dof18musc.osim model
3. Go to Tools -> CMC Tool
4. Check Actuator constraints box
5. Click the folder icon next to Actuator constraints and pick the .sto file with the controls (in this case, go to the subfolder CMC/ResultsCMC and pick "walk_subject_controls.sto" as an example).
6. Click the "edit" (pencil icon) next to the folder icon.
7. When the Select Excitations dialog box pops up, click OK.
8. When the Excitation Editor box pops up, click "Save As", and save with any name (e.g., controls.xml).

If you open the new .xml file, you'll see all the notes under x_nodes. Two more changes might need to be done for CMC to work:
1. change the ControlLinear tag to add ".excitation" to the end (see other CMC ControlConstraints files for examples of this).
2. These nodes might not work as "x_nodes" with CMC. You may have to copy these into "min_nodes" and "max_nodes"

User avatar
Takashi Yoshida
Posts: 3
Joined: Mon Nov 13, 2017 2:20 am

Re: Prescribed controller during CMC

Post by Takashi Yoshida » Wed Mar 10, 2021 6:34 am

The suggested solution works. Thank you very much.

POST REPLY