Skip to content

Commit

Permalink
Progress files and csv reports
Browse files Browse the repository at this point in the history
  • Loading branch information
tetov committed Feb 26, 2020
1 parent c48f1c5 commit ca7ff65
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 78 deletions.
13 changes: 6 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
## [0.1.21] [2020-02-26]

### Changed
- `compas_rcf.fabrication.abb_runner` now prints progress updates to Flex pendant.
- `abb_runner` now dumps list of `ClayBullets` for every bullet into file with same filename as input JSON but with IN_PROGRESS added to start.
- `abb_runner` now checks if attribute `placed` is set on `ClayBullet` and if so asks user if it should be skipped or placed (with the option to set skip and place for all future bullets with `placed` attribute). This file is deleted when script exits cleanly.
- `compas_rcf.utils.csv_` renamed to `csv_reports`. Instead of a conversion tool it now creates an opinionated report from JSON file. It can also handle directories and multiple files as inputs.

### Removed


## \[0.1.20\] \[2020-20-25\]
## \[0.1.20\] \[2020-02-25\]

### Added

Expand Down
69 changes: 61 additions & 8 deletions src/compas_rcf/fabrication/abb_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from __future__ import division
from __future__ import print_function

import json
import logging
import sys
import time
from datetime import datetime
from pathlib import Path
import json

from colorama import Fore
from colorama import Style
Expand All @@ -25,27 +25,27 @@
from compas_rrc import MoveToFrame
from compas_rrc import MoveToJoints
from compas_rrc import PrintText
from compas_rrc import ReadWatch
from compas_rrc import SetAcceleration
from compas_rrc import SetDigital
from compas_rrc import SetMaxSpeed
from compas_rrc import SetTool
from compas_rrc import SetWorkObject
from compas_rrc import WaitTime
from compas_rrc import StartWatch
from compas_rrc import StopWatch
from compas_rrc import ReadWatch
from compas_rrc import WaitTime

from compas_rcf import __version__
from compas_rcf.abb.helpers import docker_compose_paths
from compas_rcf.abb.helpers import ping
from compas_rcf.abb.helpers import robot_ips
from compas_rcf.fabrication.clay_obj import ClayBulletEncoder
from compas_rcf.fabrication.conf import abb_rcf_conf_template
from compas_rcf.fabrication.conf import fabrication_conf
from compas_rcf.utils import ui
from compas_rcf.utils.docker import compose_up
from compas_rcf.utils.json_ import load_bullets
from compas_rcf.utils.util_funcs import get_offset_frame
from compas_rcf.fabrication.clay_obj import ClayBulletEncoder

if sys.version_info[0] < 2:
raise Exception("This module requires Python 3")
Expand Down Expand Up @@ -438,7 +438,7 @@ def abb_run(cmd_line_args):
for i in range(3):
try:
logging.debug("Pinging robot")
ping(abb, timeout=5)
ping(abb, timeout=10)
logging.debug("Breaking loop after successful ping")
break
except TimeoutError:
Expand All @@ -447,7 +447,7 @@ def abb_run(cmd_line_args):
docker_compose_paths["abb_driver"], force_recreate=True, ROBOT_IP=ip
)
logging.debug("Compose up for abb_driver with robot-ip={}".format(ip))
time.sleep(10)
time.sleep(5)
else:
raise TimeoutError("Failed to connect to robot")

Expand All @@ -459,12 +459,60 @@ def abb_run(cmd_line_args):
############################################################################
# Fabrication loop #
############################################################################
json_progress_identifier = "IN_PROGRESS-"

if json_path.name.startswith(json_progress_identifier):
in_progress_json = json_path
else:
in_progress_json = json_path.with_name(
json_progress_identifier + json_path.name
)

skip_all_placed = None
place_all_placed = None

for i, bullet in enumerate(clay_bullets):
logging.info(
"Bullet {:03d}/{:03d} with id {}".format(i, len(clay_bullets), bullet.id)
current_bullet_desc = "Bullet {:03d}/{:03d} with id {}".format(
i, len(clay_bullets), bullet.id
)

if bullet.placed and not place_all_placed:
if skip_all_placed:
logging.info("Skipping " + current_bullet_desc)
continue

placed_prompt = questionary.select(
current_bullet_desc
+ " seems to have been placed already.".format(i, bullet.id),
[
"Skip",
"Skip all marked as placed in JSON",
questionary.Separator(),
"Place",
"Place all marked as placed in JSON",
],
).ask()

skip_all_placed = (
True if placed_prompt == "Skip all marked as placed in JSON" else None
)
place_all_placed = (
True if placed_prompt == "Place all marked as placed in JSON" else None
)

if (
placed_prompt == "Skip"
or placed_prompt == "Skip all marked as placed in JSON"
):
logging.info("Skipping " + current_bullet_desc)
continue

if placed_prompt == "Place":
pass

abb.send(PrintText(current_bullet_desc))
logging.info(current_bullet_desc)

pick_frame = pick_frame_from_grid(i, bullet.height)

# Pick bullet
Expand All @@ -480,10 +528,15 @@ def abb_run(cmd_line_args):
bullet.placed = time.time()
logging.debug("Time placed was {}".format(bullet.placed))

with in_progress_json.open(mode="w") as fp:
json.dump(clay_bullets, fp, cls=ClayBulletEncoder)

############################################################################
# Shutdown procedure #
############################################################################

in_progress_json.unlink() # Remove in progress json

done_json = DEFAULT_JSON_DIR / "00_done" / json_path.name

with done_json.open(mode="w") as fp:
Expand Down
25 changes: 15 additions & 10 deletions src/compas_rcf/fabrication/clay_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from __future__ import division
from __future__ import print_function

import collections
import json
import math
from itertools import count
import collections

import compas.geometry as cg
from compas import IPY
Expand Down Expand Up @@ -48,36 +48,38 @@ def __init__(
location,
trajectory_to=[],
trajectory_from=[],
id=None,
bullet_id=None,
radius=45,
height=100,
compression_ratio=0.5,
clay_density=2.0,
precision=5,
tool=None,
vkey=None,
cycle_time=None,
placed=None,
**kwargs
):
self.location = location
self.trajectory_to = trajectory_to
self.trajectory_from = trajectory_from

# sortable ID, used for fabrication sequence
if id is None:
self.id = next(self._ids)
else:
self.id = str(id) + "x" # To avoid id collisions
if not bullet_id:
self.bullet_id = next(self._ids)

self.radius = radius
self.height = height
self.compression_ratio = compression_ratio
self.tool = tool
self.vkey = vkey
if kwargs:
self.attributes = kwargs

self.cycle_time = None
self.placed = None
self.cycle_time = cycle_time
self.placed = placed

if kwargs:
for key in kwargs.keys():
setattr(self, key, kwargs[key])

@property
def location(self):
Expand Down Expand Up @@ -323,13 +325,16 @@ def from_data(cls, data):
for frame_data in data.pop("_trajectory_from"):
trajectory_from.append(Frame.from_data(frame_data))

bullet_id = data.pop("bullet_id", None)

# Take the rest of the dictionary
kwargs = data

return cls(
location,
trajectory_to=trajectory_to,
trajectory_from=trajectory_from,
bullet_id=bullet_id,
**kwargs
)

Expand Down
53 changes: 0 additions & 53 deletions src/compas_rcf/utils/csv_.py

This file was deleted.

Loading

0 comments on commit ca7ff65

Please sign in to comment.