Skip to content

Commit

Permalink
Merge pull request #166 from open-dynamic-robot-initiative/fkloss/lin…
Browse files Browse the repository at this point in the history
…e_length

Change Python line length to 88 (black default)
  • Loading branch information
luator authored Sep 20, 2023
2 parents 25d0aaa + 7a4b40d commit f6003dc
Show file tree
Hide file tree
Showing 34 changed files with 67 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length=79
max-line-length=88
ignore=E203,W503
1 change: 1 addition & 0 deletions .github/workflows/build_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
push:
branches:
- master
workflow_dispatch:

jobs:
build_and_test:
Expand Down
4 changes: 1 addition & 3 deletions demos/demo_data_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ def main():

# run the robot for a while
for _ in range(10000):
t = finger_frontend.append_desired_action(
finger.Action(torque=desired_torque)
)
t = finger_frontend.append_desired_action(finger.Action(torque=desired_torque))
finger_frontend.wait_until_timeindex(t)

# stop logger and write data to file
Expand Down
8 changes: 2 additions & 6 deletions demos/demo_simulation_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ def main():
num_fingers = finger_types_data.get_number_of_fingers(args.finger_type)
if num_fingers == 1:
finger_types = robot_interfaces.finger
create_backend = (
robot_fingers.pybullet_drivers.create_single_finger_backend
)
create_backend = robot_fingers.pybullet_drivers.create_single_finger_backend
elif num_fingers == 3:
finger_types = robot_interfaces.trifinger
create_backend = (
robot_fingers.pybullet_drivers.create_trifinger_backend
)
create_backend = robot_fingers.pybullet_drivers.create_trifinger_backend

robot_data = finger_types.SingleProcessData()

Expand Down
4 changes: 1 addition & 3 deletions demos/demo_simulation_object_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def main():
cube = collision_objects.Block()

# initialize the object tracker interface
object_tracker_data = object_tracker.Data(
"object_tracker", True, args.history_size
)
object_tracker_data = object_tracker.Data("object_tracker", True, args.history_size)
object_tracker_backend = object_tracker.SimulationBackend(
object_tracker_data, cube, real_time
)
Expand Down
4 changes: 1 addition & 3 deletions demos/demo_solo_eight.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def main():
if args.multi_process:
# In multi-process case assume that the backend is running in a
# separate process and only set up the frontend here.
robot_data = robot_interfaces.solo_eight.MultiProcessData(
"solo8", False
)
robot_data = robot_interfaces.solo_eight.MultiProcessData("solo8", False)
frontend = robot_interfaces.solo_eight.Frontend(robot_data)
else:
# In single-process case run both frontend and backend in this process
Expand Down
4 changes: 1 addition & 3 deletions demos/demo_trifinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def main():
if args.multi_process:
# In multi-process case assume that the backend is running in a
# separate process and only set up the frontend here.
robot_data = robot_interfaces.trifinger.MultiProcessData(
"trifinger", False
)
robot_data = robot_interfaces.trifinger.MultiProcessData("trifinger", False)
frontend = robot_interfaces.trifinger.Frontend(robot_data)
else:
# In single-process case run both frontend and backend in this process
Expand Down
4 changes: 1 addition & 3 deletions demos/demo_trifinger_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def main() -> None: # noqa[D103]

if t % 100 == 0:
print(f"[{t}] target joint positions: {action.position}")
print(
f"[{t}] actual joint positions: {robot_observation.position}"
)
print(f"[{t}] actual joint positions: {robot_observation.position}")

image = camera_observation.cameras[0].image
print(f"[{t}] Image shape: {image.shape}")
Expand Down
4 changes: 1 addition & 3 deletions demos/demo_trifingeredu.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def main():
if args.multi_process:
# In multi-process case assume that the backend is running in a
# separate process and only set up the frontend here.
robot_data = robot_interfaces.trifinger.MultiProcessData(
"trifinger", False
)
robot_data = robot_interfaces.trifinger.MultiProcessData("trifinger", False)
frontend = robot_interfaces.trifinger.Frontend(robot_data)
else:
# In single-process case run both frontend and backend in this process
Expand Down
4 changes: 1 addition & 3 deletions demos/demo_trifingerpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def main():
if args.multi_process:
# In multi-process case assume that the backend is running in a
# separate process and only set up the frontend here.
robot_data = robot_interfaces.trifinger.MultiProcessData(
"trifinger", False
)
robot_data = robot_interfaces.trifinger.MultiProcessData("trifinger", False)
frontend = robot_interfaces.trifinger.Frontend(robot_data)
else:
# In single-process case run both frontend and backend in this process
Expand Down
16 changes: 4 additions & 12 deletions demos/demo_trifingerpro_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@

def init_kinematics():
"""Initialise the kinematics calculator for TriFingerPro."""
robot_properties_path = get_package_share_directory(
"robot_properties_fingers"
)
urdf_file = trifinger_simulation.finger_types_data.get_finger_urdf(
"trifingerpro"
)
robot_properties_path = get_package_share_directory("robot_properties_fingers")
urdf_file = trifinger_simulation.finger_types_data.get_finger_urdf("trifingerpro")
finger_urdf_path = os.path.join(robot_properties_path, "urdf", urdf_file)
kinematics = trifinger_simulation.pinocchio_utils.Kinematics(
finger_urdf_path,
Expand All @@ -53,9 +49,7 @@ def main():
robot.initialize()
frontend = robot.frontend
else:
robot_data = robot_interfaces.trifinger.MultiProcessData(
"trifinger", False
)
robot_data = robot_interfaces.trifinger.MultiProcessData("trifinger", False)
frontend = robot_interfaces.trifinger.Frontend(robot_data)

kinematics = init_kinematics()
Expand Down Expand Up @@ -87,9 +81,7 @@ def main():
# update desired tip positions
for i in range(len(initial_cartesian_tip_positions)):
dy = distance * np.sin(t * np.pi / n_steps)
cartesian_tip_positions[i][1] = (
initial_cartesian_tip_positions[i][1] + dy
)
cartesian_tip_positions[i][1] = initial_cartesian_tip_positions[i][1] + dy

# use inverse kinematics to get the corresponding joint angles
angular_joint_positions, err = kinematics.inverse_kinematics(
Expand Down
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[tool.black]
line-length = 79

[tool.ruff]
line-length = 79

[tool.pylint.messages_control]
disable = "C0330, C0326"

Expand Down
4 changes: 1 addition & 3 deletions robot_fingers/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ def create_by_name(cls, robot_name: str, logger_buffer_size: int = 0):
Returns:
Robot: A ``Robot`` instance for the specified robot.
"""
return cls(
*robot_configs[robot_name], logger_buffer_size=logger_buffer_size
)
return cls(*robot_configs[robot_name], logger_buffer_size=logger_buffer_size)

@staticmethod
def get_supported_robots():
Expand Down
4 changes: 1 addition & 3 deletions robot_fingers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def update(self):
time_str = time.strftime("%F %H:%M")
duration_h = round((now - self.start_time) / 3600)
print(
"{} ({} h since {})".format(
time_str, duration_h, self.start_time_str
)
"{} ({} h since {})".format(time_str, duration_h, self.start_time_str)
)
self._last_time_print = now
4 changes: 1 addition & 3 deletions scripts/check_finger_position_control_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def forward_kinematics(joint_positions):
robot.frontend.wait_until_timeindex(t)

desired_tip_pos = forward_kinematics(desired_position)
actual_tip_pos = forward_kinematics(
robot.frontend.get_observation(t).position
)
actual_tip_pos = forward_kinematics(robot.frontend.get_observation(t).position)
error = desired_tip_pos - actual_tip_pos
print("Position Error: {:.3} {}".format(np.linalg.norm(error), error))
20 changes: 5 additions & 15 deletions scripts/claw_crane.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@

def loop(win, args):
title = "Claw Crane"
status_line = (
" q: quit | a/d: x-axis | w/s: y-axis | r/f: z-axis | q/e: open/close"
)
status_line = " q: quit | a/d: x-axis | w/s: y-axis | r/f: z-axis | q/e: open/close"

robot_properties_path = get_package_share_directory(
"robot_properties_fingers"
)
urdf_file = trifinger_simulation.finger_types_data.get_finger_urdf(
"trifingerpro"
)
robot_properties_path = get_package_share_directory("robot_properties_fingers")
urdf_file = trifinger_simulation.finger_types_data.get_finger_urdf("trifingerpro")
finger_urdf_path = os.path.join(robot_properties_path, "urdf", urdf_file)
kinematics = trifinger_simulation.pinocchio_utils.Kinematics(
finger_urdf_path,
Expand All @@ -53,9 +47,7 @@ def loop(win, args):
try:
while True:
steps = 200
joint_pos_step_size = (
target_joint_pos - current_joint_pos
) / steps
joint_pos_step_size = (target_joint_pos - current_joint_pos) / steps

for _ in range(50):
current_joint_pos += joint_pos_step_size
Expand All @@ -65,9 +57,7 @@ def loop(win, args):

gui.update_screen(
[
"Center: ({:.3f}, {:.3f}, {:.3f})".format(
*center_position
),
"Center: ({:.3f}, {:.3f}, {:.3f})".format(*center_position),
"Tips to Center: {:.3f}".format(dist_tips_to_center),
"",
]
Expand Down
8 changes: 2 additions & 6 deletions scripts/construct_object_reset_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,10 @@ def main():
swipes_120 = connect_swipes(initial_pos_120, swipes_120, jump_speed_mps)
swipes_240 = connect_swipes(initial_pos_240, swipes_240, jump_speed_mps)

joint_trajectory = trajectory_ik(
swipes_0, swipes_120, swipes_240, args.visualize
)
joint_trajectory = trajectory_ik(swipes_0, swipes_120, swipes_240, args.visualize)

header = ["observation_position_%d" % i for i in range(9)]
np.savetxt(
args.out_file, joint_trajectory, header=" ".join(header), comments=""
)
np.savetxt(args.out_file, joint_trajectory, header=" ".join(header), comments="")


if __name__ == "__main__":
Expand Down
8 changes: 2 additions & 6 deletions scripts/demonstrate_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ def loop(win, args):
return
elif pressed_key == ord(" "):
if is_recording:
robot.logger.stop_and_save(
args.outfile, robot.logger.Format.CSV
)
robot.logger.stop_and_save(args.outfile, robot.logger.Format.CSV)
else:
robot.logger.start()

Expand All @@ -122,9 +120,7 @@ def main():
choices=robot_fingers.Robot.get_supported_robots(),
help="Name of the robot.",
)
parser.add_argument(
"outfile", type=str, help="Output file for the recorded data."
)
parser.add_argument("outfile", type=str, help="Output file for the recorded data.")
args = parser.parse_args()

curses.wrapper(lambda stdscr: loop(stdscr, args))
Expand Down
15 changes: 4 additions & 11 deletions scripts/evaluate_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
def compute_reward_move_cube(task, log, t, goal):
camera_observation = log.get_camera_observation(t)
cube_pose = camera_observation.filtered_object_pose
reward = -task.evaluate_state(
goal["goal"], cube_pose, int(goal["difficulty"])
)
reward = -task.evaluate_state(goal["goal"], cube_pose, int(goal["difficulty"]))
return reward


Expand All @@ -27,18 +25,15 @@ def compute_reward_move_cube_on_trajectory(task, log, t, goal):
return reward


def compute_reward_rearrange_dice(
task, log, t, goal, goal_masks, reward_cache
):
def compute_reward_rearrange_dice(task, log, t, goal, goal_masks, reward_cache):
camera_observation = log.get_camera_observation(t)
# use timestamp of the first camera to identify the observation
stamp = camera_observation.cameras[0].timestamp

# only compute the reward if it is not yet in the cache
if stamp not in reward_cache:
masks = tuple(
segment_image(convert_image(c.image))
for c in camera_observation.cameras
segment_image(convert_image(c.image)) for c in camera_observation.cameras
)
reward_cache[stamp] = -task.evaluate_state(goal_masks, masks)

Expand Down Expand Up @@ -111,9 +106,7 @@ def main():
camera_log = str(args.log_dir / "camera_data.dat")

if args.task in ("move_cube", "move_cube_on_trajectory"):
log = robot_fingers.TriFingerPlatformWithObjectLog(
robot_log, camera_log
)
log = robot_fingers.TriFingerPlatformWithObjectLog(robot_log, camera_log)
else:
log = robot_fingers.TriFingerPlatformLog(robot_log, camera_log)
except Exception as e:
Expand Down
9 changes: 2 additions & 7 deletions scripts/fingeredu_endurance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,11 @@ def main():
)

finger_data = robot_interfaces.finger.SingleProcessData()
backend = robot_fingers.create_real_finger_backend(
finger_data, config_file_path
)
backend = robot_fingers.create_real_finger_backend(finger_data, config_file_path)
finger = robot_interfaces.finger.Frontend(finger_data)
backend.initialize()

input(
"Verify that finger is pointing straight down."
" Press Enter to continue."
)
input("Verify that finger is pointing straight down." " Press Enter to continue.")

demo_position_commands(finger)

Expand Down
4 changes: 1 addition & 3 deletions scripts/fingerpro_endurance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ def move_on_full_range(push_interval):
config.soft_position_limits_upper = [np.inf] * n_joints

robot_data = robot_interfaces.finger.SingleProcessData()
robot_backend = robot_fingers.create_real_finger_backend(
robot_data, config
)
robot_backend = robot_fingers.create_real_finger_backend(robot_data, config)
robot_frontend = robot_interfaces.finger.Frontend(robot_data)

robot_backend.initialize()
Expand Down
12 changes: 3 additions & 9 deletions scripts/joint_friction_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def run_application(stdscr, robot, velocity_radps, buffer_size):

line += 2
stdscr.addstr(line, 0, "Status:", curses.A_BOLD)
stdscr.addstr(
line, len("Status:") + 1, "RUNNING" if enabled else "STOPPED"
)
stdscr.addstr(line, len("Status:") + 1, "RUNNING" if enabled else "STOPPED")

line += 2
stdscr.addstr(line, 0, "Commanded Torque:", curses.A_BOLD)
Expand All @@ -140,16 +138,12 @@ def run_application(stdscr, robot, velocity_radps, buffer_size):
)

line += 2
stdscr.addstr(
line, 0, "Velocity (actual / desired):", curses.A_BOLD
)
stdscr.addstr(line, 0, "Velocity (actual / desired):", curses.A_BOLD)
for i, (p, d) in enumerate(
zip(velocity_buffer.mean(), desired_velocity_radps)
):
line += 1
stdscr.addstr(
line, 4, "Joint {}: {:.3f} / {:3f}".format(i, p, d)
)
stdscr.addstr(line, 4, "Joint {}: {:.3f} / {:3f}".format(i, p, d))

stdscr.refresh()

Expand Down
8 changes: 2 additions & 6 deletions scripts/plot_post_submission_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ def read_file(filename):

def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"logfiles", nargs="+", type=pathlib.Path, help="logfiles"
)
parser.add_argument("logfiles", nargs="+", type=pathlib.Path, help="logfiles")
parser.add_argument(
"--no-display",
dest="use_display",
Expand All @@ -75,9 +73,7 @@ def main():
position_displacement = [
np.linalg.norm(s["position"]["mean"][:2]) for s in data
]
mean_confidence = [
s["confidence"]["object_mean_confidence"] for s in data
]
mean_confidence = [s["confidence"]["object_mean_confidence"] for s in data]
position_mean_error = [s["position"]["mean_error"] for s in data]
orientation_mean_error = [s["orientation"]["mean_error"] for s in data]

Expand Down
Loading

0 comments on commit f6003dc

Please sign in to comment.