-
Notifications
You must be signed in to change notification settings - Fork 1
Add passive joint moments #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f8da7dc
First draft of passive moments in gait2d (not working yet)
tvdbogert e83812b
symbols qmin, qmax now added to segment constants
tvdbogert c206de7
example_constants.yml: qmin and qmax specified in radians
tvdbogert e31a75c
example_constants.yml: corrected sign error in qminc
tvdbogert 9da7f44
gait2de.c is back in the repository
tvdbogert a157462
Remove gait2de.c.
moorepants File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,3 +78,4 @@ docs/_build/ | |
| *.i*86 | ||
| *.x86_64 | ||
| *.hex | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -339,6 +339,7 @@ def derive_equations_of_motion( | |||||
| treadmill=False, | ||||||
| hand_of_god=True, | ||||||
| stiffness_exp=3, | ||||||
| passive_torques=False, | ||||||
| ): | ||||||
| """Returns the equations of motion for the planar walking model along with | ||||||
| all of the constants, coordinates, speeds, joint torques, visualization | ||||||
|
|
@@ -368,6 +369,8 @@ def derive_equations_of_motion( | |||||
| the torso and a torque acting on the torso will be included. | ||||||
| stiffness_exp : float, optional | ||||||
| Exponent of the contact force stiffness force. | ||||||
| passive_torques : boolean, optional | ||||||
| If true, a nonlinear passive torque function is added. | ||||||
|
|
||||||
| Returns | ||||||
| ======= | ||||||
|
|
@@ -420,10 +423,12 @@ def derive_equations_of_motion( | |||||
| for label in sorted(segment_descriptions.keys()): | ||||||
|
|
||||||
| segment_class, desc, joint_desc = segment_descriptions[label] | ||||||
|
|
||||||
| passive_torque = passive_torques # true or false for this particular segment | ||||||
|
|
||||||
| if label == 'A': # trunk | ||||||
| parent_reference_frame = ground | ||||||
| origin_joint = origin | ||||||
| passive_torque = False # no passive torque between ground and trunk | ||||||
| elif label == 'E': # left thigh | ||||||
| # For the left thigh, set the trunk and hip as the | ||||||
| # reference_frame and origin joint. | ||||||
|
|
@@ -434,7 +439,7 @@ def derive_equations_of_motion( | |||||
| origin_joint = segments[-1].joint | ||||||
|
|
||||||
| segment = segment_class(label, desc, parent_reference_frame, | ||||||
| origin_joint, joint_desc, ground) | ||||||
| origin_joint, joint_desc, ground, passive_torque) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| segments.append(segment) | ||||||
|
|
||||||
| # constants, coordinates, speeds, kinematic differential equations | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -57,7 +57,7 @@ class BodySegment(object): | |||||
| viz_cylinder_radius = 0.035 # meters | ||||||
|
|
||||||
| def __init__(self, label, description, parent_reference_frame, | ||||||
| origin_joint, joint_description, inertial_frame): | ||||||
| origin_joint, joint_description, inertial_frame, passive_torque=False): | ||||||
| """Initializes a body segment.""" | ||||||
|
|
||||||
| self.label = label | ||||||
|
|
@@ -66,6 +66,7 @@ def __init__(self, label, description, parent_reference_frame, | |||||
| self.origin_joint = origin_joint | ||||||
| self.joint_description = joint_description | ||||||
| self.inertial_frame = inertial_frame | ||||||
| self.passive_torque = passive_torque; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| self._create_symbols() | ||||||
| self._kinematic_differential_equations() | ||||||
|
|
@@ -112,6 +113,13 @@ def _create_symbols(self): | |||||
| self.mass_center_x_symbol, | ||||||
| self.mass_center_y_symbol] | ||||||
|
|
||||||
| if self.passive_torque: | ||||||
| # we need these constants to define the passive range of motion | ||||||
| self.qmin_symbol = symbols('qmin{}'.format(subscript), **sym_kwargs) | ||||||
| self.qmax_symbol = symbols('qmax{}'.format(subscript), **sym_kwargs) | ||||||
| self.constants.append(self.qmin_symbol) | ||||||
| self.constants.append(self.qmax_symbol) | ||||||
|
|
||||||
| # functions of time | ||||||
| self.generalized_coordinate_symbol = \ | ||||||
| time_varying('q{}'.format(subscript)) | ||||||
|
|
@@ -183,8 +191,33 @@ def _create_rigid_body(self): | |||||
|
|
||||||
| def _joint_torque(self): | ||||||
| """Creates the joint torque vector acting on the segment.""" | ||||||
| self.torque = self.joint_torque_symbol * self.reference_frame.z | ||||||
| # TODO : add in passive joint stiffness and damping | ||||||
| torque = self.joint_torque_symbol | ||||||
|
|
||||||
| # add in passive joint stiffness and damping | ||||||
| if self.passive_torque: | ||||||
| # hard-coded parameters, these are not critical | ||||||
| k1 = 1.0 # linear stiffness (Nm/rad) | ||||||
| k2 = 5000.0 # quadratic stiffness (Nm/rad^2) applied when outside the qmin to qmax range | ||||||
| b = 1.0 # linear damping (Nms/rad) | ||||||
|
|
||||||
| # turn the three terms off individually, for testing | ||||||
| # currently, setting k1 and k2 to zero makes it work. | ||||||
| # k1 = 0.0; | ||||||
| # k2 = 0.0; | ||||||
| # b = 0.0; | ||||||
|
|
||||||
| # add a weak linear stiffness and damping | ||||||
| torque += -k1 * self.generalized_coordinate_symbol - b * self.generalized_speed_symbol | ||||||
|
|
||||||
| # add quadratic stiffness when angle is outside the range qmin to qmax | ||||||
| qmaxdiff = self.generalized_coordinate_symbol - self.qmax_symbol | ||||||
| qmaxpenetration = (Abs(qmaxdiff) + qmaxdiff) / 2 # this is a positive value | ||||||
| qmindiff = self.qmin_symbol - self.generalized_coordinate_symbol | ||||||
| qminpenetration = (Abs(qmindiff) + qmindiff) / 2 # this is a positive value | ||||||
| torque += -k2 * (qmaxpenetration**2 - qminpenetration**2); | ||||||
|
|
||||||
| # apply this torque on the Z axis of the segment | ||||||
| self.torque = torque * self.reference_frame.z | ||||||
|
|
||||||
| def _gravity(self): | ||||||
| """Creates the gravitational force vector acting on the segment.""" | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.