Cocofest
: Custom Optimal Control Optimization for Functional Electrical STimulation, is an optimal control program (OCP) package for functional electrical stimulation (FES).
It is based on the bioptim framework for the optimal control construction.
Bioptim uses biorbd a biomechanics library and benefits from the powerful algorithmic diff provided by CasADi.
To solve the OCP, the robust solver Ipopt has been implemented.
Type | Status |
---|---|
License | |
Code coverage | |
Code climate |
Currently, no anaconda installation is available. The installation must be done from the sources. Cloning the repository is the first step to be able to use the package.
Cocofest
relies on several libraries.
Follows the steps to install everything you need to use Cocofest
.
First, you need to create a new conda environment
conda create -n YOUR_ENV_NAME python=3.11
Then, activate the environment
conda activate YOUR_ENV_NAME
This step will allow you to install the dependencies in the environment much quicker
conda install -cconda-forge conda-libmamba-solver
After, install the dependencies
conda install numpy matplotlib pytest casadi biorbd pyorerun -cconda-forge --solver=libmamba
Finally, install the bioptim setup.py file located in your cocofest/external/bioptim folder
cd <path_up_to_cocofest_file>/external/bioptim
python setup.py install
You are now ready to use Cocofest
!
All models are implemented at the muscle actuator level, making them applicable to a wide range of problems regardless of the specific optimal control problem.
Model Name | Citation | Description / Focus |
---|---|---|
Veltink1992 | Veltink, P. H., Chizeck, H. J., Crago, P. E., & El-Bialy, A. (1992). Nonlinear joint angle control for artificially stimulated muscle. IEEE Transactions on Biomedical Engineering, 39(4), 368–380. | Nonlinear control of joint angles via electrical stimulation. |
Riener1996 | Riener, R., Quintern, J., & Schmidt, G. (1996). Biomechanical model of the human knee evaluated by neuromuscular stimulation. Journal of Biomechanics, 29(9), 1157–1167. | Biomechanical knee model validated using neuromuscular stimulation. |
Ding2003 | Ding, J., Wexler, A. S., & Binder-Macleod, S. A. (2003). Mathematical models for fatigue minimization during functional electrical stimulation. Journal of Electromyography and Kinesiology, 13(6), 575–588. | Focus on mathematical models for minimising fatigue. |
Ding2007 | Ding, J., Chou, L. W., Kesar, T. M., et al. (2007). Mathematical model that predicts the force–intensity and force–frequency relationships after spinal cord injuries. Muscle & Nerve, 36(2), 214–222. | Predicts force–intensity and force–frequency responses post-SCI. |
Marion2009 | Marion, M. S., Wexler, A. S., Hull, M. L., & Binder-Macleod, S. A. (2009). Predicting the effect of muscle length on fatigue during electrical stimulation. Muscle & Nerve, 40(4), 573–581. | Examines muscle length impact on fatigue under stimulation. |
Marion2013 | Marion, M. S., Wexler, A. S., & Hull, M. L. (2013). Predicting non-isometric fatigue induced by electrical stimulation pulse trains as a function of pulse duration. Journal of NeuroEngineering and Rehabilitation, 10, 1–16. | Predicts non-isometric fatigue based on pulse duration. |
Hmed2018 | Hmed, A. B., Bakir, T., Sakly, A., & Binczak, S. (2018). A new mathematical force model that predicts the force-pulse amplitude relationship of human skeletal muscle. In IEEE EMBC, pp. 3485–3488. | Models the relationship between pulse amplitude and force. |
You can create your own FES OCP by following the steps below:
- Create a new python file
- Import the desired model from
Cocofest
(e.g. Ding2003) and the fes_ocp class
from cocofest import DingModelFrequency, OcpFes
- Create your own optimal control problem by adding the stimulation pulse number, the number of shooting points, the final simulation time, the objective function (for this example, the force at the end of the simulation must be the closest to 100N), the minimum and maximum time between two stimulation pulse, the time bimapping (If True, will act like a frequency at constant pulse interval).
ocp = OcpFes().prepare_ocp(...,
n_stim=10,
n_shooting=20,
...,)
- Solve you OCP
result = ocp.solve()
You can find all the available examples in the examples file.
The following example is a musculoskeletal model driven by the Ding2007 FES model. The objective function is to reach a 90° forearm position and 0° arm position at the movement end. The stimulation last 1s and the stimulation frequency is 10Hz. The optimized parameter are each stimulation pulse width.
You can also compute the models form initial value problem. For that, use the IvpFes class to build the computed problem.
from cocofest import IvpFes, DingModelFrequencyWithFatigue
fes_parameters = {"model": DingModelFrequencyWithFatigue(), "n_stim": 10}
ivp_parameters = {"n_shooting": 20, "final_time": 1}
ivp = IvpFes(fes_parameters, ivp_parameters)
result, time = ivp.integrate()
The summation truncation is an integer parameter that can be added to the model. It will truncate the stimulation apparition list used for the calcium summation. The integer number defines the stimulation number to keep prior this summation calculation (e.g only the 5 past stimulation will be included).
ocp = OcpFes().prepare_ocp(model=DingModelFrequency(sum_stim_truncation=5))
Cocofest
is not yet published in a journal.
But if you use Cocofest
in your research, please kindly cite this zenodo link 10.5281/zenodo.10427934.
The software development was supported by Ingénierie de technologies interactives en réadaptation INTER #160 OptiStim. The Cocofest logo has been design by MaxMV