Skip to content

Commit

Permalink
v0.1.1 bug fixes, syntax fixes, and update to 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zmk5 committed Mar 28, 2024
1 parent 8a6f28e commit 8dbfcb6
Show file tree
Hide file tree
Showing 37 changed files with 920 additions and 386 deletions.
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ classifiers = [
dependencies = [
"aiortc",
"black",
"bosdyn-api==3.3.2",
"bosdyn-choreography-client==3.3.2",
"bosdyn-client==3.3.2",
"bosdyn-core==3.3.2",
"bosdyn-mission==3.3.2",
"bosdyn-api==4.0.0",
"bosdyn-choreography-client==4.0.0",
"bosdyn-client==4.0.0",
"bosdyn-core==4.0.0",
"bosdyn-mission==4.0.0",
"graphviz",
"numpy==1.24.1",
"opencv-python==4.5.*",
"Pillow",
Expand Down
49 changes: 22 additions & 27 deletions scripts/demo_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,32 @@
from bosdyn.client.math_helpers import SE3Pose

import py_trees
from py_trees.composites import Sequence

from spot_bt.data import Blackboards
from spot_bt.data import ArmPose, ArmPoses
from spot_bt.behaviors.actions.general import ClaimLease, RobotPowerOff, RobotPowerOn
from spot_bt.behaviors.actions.arm import ArmStow, ArmUnstow
from spot_bt.behaviors.actions.arm import CloseGripper, OpenGripper
from spot_bt.behaviors.actions.arm import ArmTrajectory, ArmTrajectories
from spot_bt.behaviors.actions.arm import ArmTrajectories
from spot_bt.composites.selector import create_undock_selector
from spot_bt.composites.sequence import create_dock_sequence
from spot_bt.composites.sequence import create_undock_sequence
from spot_bt.tick import generic_pre_tick_handler



def create_root() -> py_trees.composites.Sequence:
def create_root() -> Sequence:
"""Create the root for the Autonomy capability."""
root = py_trees.composites.Sequence("DemoArm", memory=True)

root.add_child(create_undock_sequence())
root = Sequence("DemoArm", memory=True)
root.add_children(
[
ClaimLease(name="claim_lease"),
RobotPowerOn(name="power_on"),
create_undock_selector(),
ArmUnstow(name="unstow_arm"),
# ArmTrajectory(name="move_arm_to_postion"),
ArmTrajectories(name="move_arm_to_postions"),
OpenGripper(name="open_gripper"),
ArmTrajectories(name="move_arm_to_postions"),
CloseGripper(name="close_gripper"),
ArmStow(name="stow_arm"),
RobotPowerOff(name="power_off"),
create_dock_sequence(),
]
)
root.add_child(create_dock_sequence())

py_trees.display.render_dot_tree(root)

Expand All @@ -54,8 +48,7 @@ def main():
raise ValueError(
"The SPOT_IP environment variable was not set."
)
else:
robot = sdk.create_robot(spot_ip)
robot = sdk.create_robot(spot_ip)
bosdyn.client.util.authenticate(robot)
robot.time_sync.wait_for_sync()

Expand All @@ -65,32 +58,34 @@ def main():
blackboard = Blackboards()
blackboard.state = py_trees.blackboard.Client(name="State")
blackboard.state.register_key(key="robot", access=py_trees.common.Access.WRITE)
blackboard.state.register_key(key="dock_id", access=py_trees.common.Access.WRITE)
blackboard.state.register_key(key="pose", access=py_trees.common.Access.WRITE)
blackboard.state.robot = robot
blackboard.state.register_key(key="dock_id", access=py_trees.common.Access.WRITE)
blackboard.state.dock_id = 549
blackboard.state.register_key(key="is_docked", access=py_trees.common.Access.WRITE)
blackboard.state.is_docked = True
blackboard.state.register_key(
key="is_gripper_open", access=py_trees.common.Access.WRITE
)
blackboard.state.is_gripper_open = False

blackboard.arm = py_trees.blackboard.Client(name="Arm")
blackboard.arm.register_key(key="target", access=py_trees.common.Access.WRITE)
blackboard.arm.register_key(key="command", access=py_trees.common.Access.WRITE)
# blackboard.arm.target = ArmPose(
# SE3Pose(x=1.0, y=0.0, z=0.5, rot=[1.0, 0.0, 0.0, 0.0]),
# False,
# )
blackboard.arm.command = None
blackboard.arm.register_key(key="target", access=py_trees.common.Access.WRITE)
blackboard.arm.target = ArmPoses([
ArmPose(
SE3Pose(x=1.0, y=0.0, z=0.0, rot=[1.0, 0.0, 0.0, 0.0]),
SE3Pose(x=0.9, y=0.0, z=0.0, rot=[1.0, 0.0, 0.0, 0.0]),
False,
),
ArmPose(
SE3Pose(x=1.0, y=0.5, z=0.0, rot=[1.0, 0.0, 0.0, 0.0]),
SE3Pose(x=0.9, y=0.5, z=0.0, rot=[1.0, 0.0, 0.0, 0.0]),
False,
),
ArmPose(
SE3Pose(x=1.0, y=0.0, z=0.5, rot=[1.0, 0.0, 0.0, 0.0]),
SE3Pose(x=0.9, y=0.0, z=0.5, rot=[1.0, 0.0, 0.0, 0.0]),
False,
),
])
blackboard.arm.command = None

# Create and execute behavior tree
lease_client = robot.ensure_client(
Expand Down
117 changes: 117 additions & 0 deletions scripts/demo_arm_no_dock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
"""spot_bt Arm Demonstration."""
from __future__ import annotations

import os
import time

import bosdyn.client
import bosdyn.client.util
from bosdyn.client.math_helpers import SE3Pose

import py_trees
from py_trees.composites import Sequence

from spot_bt.data import Blackboards
from spot_bt.data import ArmPose, ArmPoses
from spot_bt.behaviors.actions.general import RobotPowerOff, RobotPowerOn
from spot_bt.behaviors.actions.arm import ArmStow, ArmUnstow
from spot_bt.behaviors.actions.arm import CloseGripper, OpenGripper
from spot_bt.behaviors.actions.arm import ArmTrajectories
from spot_bt.tick import generic_pre_tick_handler


def create_root() -> Sequence:
"""Create the root for the Autonomy capability."""
root = Sequence("DemoArm", memory=True)
root.add_children(
[
RobotPowerOn(name="power_on"),
ArmUnstow(name="unstow_arm"),
OpenGripper(name="open_gripper"),
ArmTrajectories(name="move_arm_to_postions"),
CloseGripper(name="close_gripper"),
ArmStow(name="stow_arm"),
RobotPowerOff(name="power_off"),
]
)
py_trees.display.render_dot_tree(root)

return root


def main():
sdk = bosdyn.client.create_standard_sdk("spot_bt_fiducial_demo")
spot_ip = os.getenv("SPOT_IP")
if spot_ip is None:
raise ValueError(
"The SPOT_IP environment variable was not set."
)
robot = sdk.create_robot(spot_ip)
bosdyn.client.util.authenticate(robot)
robot.time_sync.wait_for_sync()

# Create behavior tree and blackboard
py_trees.logging.level = py_trees.logging.Level.DEBUG
py_trees.blackboard.Blackboard.enable_activity_stream(maximum_size=100)
blackboard = Blackboards()
blackboard.state = py_trees.blackboard.Client(name="State")
blackboard.state.register_key(key="robot", access=py_trees.common.Access.WRITE)
blackboard.state.robot = robot
blackboard.state.register_key(key="dock_id", access=py_trees.common.Access.WRITE)
blackboard.state.dock_id = 549
blackboard.state.register_key(key="is_docked", access=py_trees.common.Access.WRITE)
blackboard.state.is_docked = True
blackboard.state.register_key(
key="is_gripper_open", access=py_trees.common.Access.WRITE
)
blackboard.state.is_gripper_open = False

blackboard.arm = py_trees.blackboard.Client(name="Arm")
blackboard.arm.register_key(key="command", access=py_trees.common.Access.WRITE)
blackboard.arm.command = None
blackboard.arm.register_key(key="target", access=py_trees.common.Access.WRITE)
blackboard.arm.target = ArmPoses([
ArmPose(
SE3Pose(x=1.0, y=0.0, z=0.0, rot=[1.0, 0.0, 0.0, 0.0]),
False,
),
ArmPose(
SE3Pose(x=1.0, y=0.5, z=0.0, rot=[1.0, 0.0, 0.0, 0.0]),
False,
),
ArmPose(
SE3Pose(x=1.0, y=0.0, z=0.5, rot=[1.0, 0.0, 0.0, 0.0]),
False,
),
])

# Create and execute behavior tree
lease_client = robot.ensure_client(
bosdyn.client.lease.LeaseClient.default_service_name
)
with bosdyn.client.lease.LeaseKeepAlive(
lease_client, must_acquire=True, return_at_exit=True
):
# Create visitors
debug_visitor = py_trees.visitors.DebugVisitor()

# Enable tree stewardship
root = create_root()
behavior_tree = py_trees.trees.BehaviourTree(root)
behavior_tree.add_pre_tick_handler(generic_pre_tick_handler)
behavior_tree.visitors.append(debug_visitor)
# behavior_tree.add_post_tick_handler(generic_post_tick_handler)
behavior_tree.setup(timeout=15)
root.setup_with_descendants()

# Begin autonomy loop
while True:
try:
behavior_tree.tick()
time.sleep(0.1)
except KeyboardInterrupt:
break


if __name__ == "__main__":
main()
58 changes: 22 additions & 36 deletions scripts/demo_autonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,36 @@

import py_trees

from spot_bt.data import Blackboards
from spot_bt.data import Pose
from spot_bt.data import Blackboards, Pose
from spot_bt.behaviors.actions.general import RobotState
from spot_bt.behaviors.actions.movement import MoveToFiducial
from spot_bt.behaviors.actions.movement import RobotPose
from spot_bt.behaviors.actions.movement import TurnInPlace
from spot_bt.behaviors.actions.perception import DetectFiducialMarkers
from spot_bt.behaviors.actions.perception import DetectWorldObjects
from spot_bt.composites.selector import create_generic_fiducial_selector
from spot_bt.behaviors.actions.movement import MoveToFiducial, RobotPose, TurnInPlace
from spot_bt.behaviors.actions.perception import DetectFiducialMarkers, DetectWorldObjects
from spot_bt.composites.selector import create_generic_fiducial_selector, create_undock_selector
from spot_bt.composites.sequence import create_dock_sequence
from spot_bt.composites.sequence import create_undock_sequence
from spot_bt.tick import generic_pre_tick_handler


def create_root() -> py_trees.composites.Sequence:
"""Create the root for the Autonomy capability."""
root = py_trees.composites.Sequence("DemoAutonomy", memory=True)
get_robot_state = RobotState(name="Get Spot State")
set_robot_pose = RobotPose(name="Set Spot Pose")
turn_90_0 = TurnInPlace("Turn 0 -> 90")
turn_90_1 = TurnInPlace("Turn 90 -> 180")
turn_90_2 = TurnInPlace("Turn 180 -> 270")
turn_90_3 = TurnInPlace("Turn 270 -> 360")
detect_objects = DetectWorldObjects(name="Detect World Objects")
detect_fiducials = DetectFiducialMarkers(name="Detect Fiducials")

root.add_child(create_undock_sequence())
root.add_children(
[
get_robot_state,
set_robot_pose,
turn_90_0,
turn_90_1,
turn_90_2,
turn_90_3,
detect_objects,
detect_fiducials,
]
)
root.add_child(create_generic_fiducial_selector())
root.add_children(
[
create_undock_selector(),
RobotState(name="Get Spot State"),
RobotPose(name="Set Spot Pose"),
TurnInPlace("Turn 0 -> 90"),
TurnInPlace("Turn 90 -> 180"),
TurnInPlace("Turn 180 -> 270"),
TurnInPlace("Turn 270 -> 360"),
DetectWorldObjects(name="Detect World Objects"),
DetectFiducialMarkers(name="Detect Fiducials"),
create_generic_fiducial_selector(),
RobotState(name="Get Spot State"),
MoveToFiducial(name="Move to Fiducial"),
create_dock_sequence(),
]
)
root.add_child(create_dock_sequence())
py_trees.display.render_dot_tree(root)

return root

Expand All @@ -79,20 +62,23 @@ def main():
blackboard = Blackboards()
blackboard.state = py_trees.blackboard.Client(name="State")
blackboard.state.register_key(key="robot", access=py_trees.common.Access.WRITE)
blackboard.state.register_key(key="dock_id", access=py_trees.common.Access.WRITE)
blackboard.state.register_key(key="pose", access=py_trees.common.Access.WRITE)
blackboard.state.robot = robot
blackboard.state.register_key(key="dock_id", access=py_trees.common.Access.WRITE)
blackboard.state.dock_id = 549
blackboard.state.register_key(key="pose", access=py_trees.common.Access.WRITE)
blackboard.state.pose = Pose()
blackboard.state.pose.set_pose(yaw=0.4, roll=0.0, pitch=0.0)
blackboard.state.register_key(key="is_docked", access=py_trees.common.Access.WRITE)
blackboard.state.is_docked = True

blackboard.perception = py_trees.blackboard.Client(name="Perception")
blackboard.perception.register_key(
key="fiducials", access=py_trees.common.Access.WRITE
)
blackboard.perception.fiducials = None
blackboard.perception.register_key(
key="world_objects", access=py_trees.common.Access.WRITE
)
blackboard.perception.fiducials = None
blackboard.perception.world_objects = None

# Create and execute behavior tree
Expand Down
Loading

0 comments on commit 8dbfcb6

Please sign in to comment.