The task is quite complex even for simple examples.
The idea is that you create artificial muscles between the hand and ball to enable contact when the ball is in the hand. This requires artificial muscles for all 6 DOF in both the push and pull direction = 12 muscles.
These muscles must use an instance of the
AnyMuscleModelUsr1 which can define the strength of the muscle model as a function. This function you define so that the muscles have strength when the ball is in contact with the hand and no strength when the ball is released.
Addtionally you create the same elements for when the ball is out of the hand. Here you define the artificial muscles between the ball and the global coordiante system. Again with 12 muscles and a AnyMuscleModelUsr1 with the opposite strength function. This one should be 0 when the ball is in the hand and high when the ball is not carried by the hand.
To better understand these elements and how it looks. Here is a link to a example model.
This one simulates a dumbbell curl where the dumbbell is removed midway through the simulation.
The strength functions here are time dependent but can also rely on other measures.
Look at the elements in the Environment and EnvironmentConnection folders to see what you must add to your model.