-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from olincollege/logging
Added Python Logging
- Loading branch information
Showing
19 changed files
with
133 additions
and
112 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ py_library( | |
srcs = [ | ||
"__init__.py", | ||
"utils.py", | ||
"logging.py", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
from common.utils import * | ||
from common.logging import * |
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import logging | ||
from pydrake.common import configure_logging | ||
|
||
|
||
def init_logging(): | ||
configure_logging() | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
logging.getLogger("drake").setLevel(logging.INFO) |
This file contains 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 |
---|---|---|
@@ -1,7 +1,69 @@ | ||
from pydrake.multibody.parsing import Parser | ||
from pydrake.all import * | ||
|
||
|
||
def ConfigureParser(parser: Parser): | ||
"""Add the models/package.xml index to the given Parser.""" | ||
package_xml = "models/package.xml" | ||
parser.package_map().AddPackageXml(filename=package_xml) | ||
|
||
|
||
class PoseTransform(LeafSystem): | ||
def __init__( | ||
self, | ||
X_BA: RigidTransform = RigidTransform(), | ||
): | ||
LeafSystem.__init__(self) | ||
self.DeclareAbstractInputPort("pose", AbstractValue.Make(RigidTransform())) | ||
self.DeclareAbstractOutputPort( | ||
"pose", | ||
lambda: AbstractValue.Make(RigidTransform()), | ||
self._CalcOutput, | ||
) | ||
self.X_BA = X_BA | ||
|
||
def _CalcOutput(self, context, output): | ||
pose = self.EvalAbstractInput(context, 0).get_value() | ||
pose = pose @ self.X_BA | ||
output.get_mutable_value().set(pose.rotation(), pose.translation()) | ||
|
||
|
||
# Credit to https://github.com/RussTedrake/manipulation | ||
def AddMeshcatTriad( | ||
meshcat: Meshcat, | ||
path: str, | ||
length: float = 0.25, | ||
radius: float = 0.01, | ||
opacity: float = 1.0, | ||
X_PT: RigidTransform = RigidTransform(), | ||
): | ||
"""Adds an X-Y-Z triad to the meshcat scene. | ||
Args: | ||
meshcat: A Meshcat instance. | ||
path: The Meshcat path on which to attach the triad. Using relative paths will attach the triad to the path's coordinate system. | ||
length: The length of the axes in meters. | ||
radius: The radius of the axes in meters. | ||
opacity: The opacity of the axes in [0, 1]. | ||
X_PT: The pose of the triad relative to the path. | ||
""" | ||
meshcat.SetTransform(path, X_PT) | ||
# x-axis | ||
X_TG = RigidTransform(RotationMatrix.MakeYRotation(np.pi / 2), [length / 2.0, 0, 0]) | ||
meshcat.SetTransform(path + "/x-axis", X_TG) | ||
meshcat.SetObject( | ||
path + "/x-axis", Cylinder(radius, length), Rgba(1, 0, 0, opacity) | ||
) | ||
|
||
# y-axis | ||
X_TG = RigidTransform(RotationMatrix.MakeXRotation(np.pi / 2), [0, length / 2.0, 0]) | ||
meshcat.SetTransform(path + "/y-axis", X_TG) | ||
meshcat.SetObject( | ||
path + "/y-axis", Cylinder(radius, length), Rgba(0, 1, 0, opacity) | ||
) | ||
|
||
# z-axis | ||
X_TG = RigidTransform([0, 0, length / 2.0]) | ||
meshcat.SetTransform(path + "/z-axis", X_TG) | ||
meshcat.SetObject( | ||
path + "/z-axis", Cylinder(radius, length), Rgba(0, 0, 1, opacity) | ||
) |
This file contains 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.