Skip to content

Commit

Permalink
feat(arcor2_fit_demo): new OTs for simulated actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ZdenekM committed Mar 21, 2024
1 parent e0e766c commit 335697b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/docker/arcor2_upload_fit_demo/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
docker_image(name="arcor2_upload_fit_demo", repository="arcor2/arcor2_upload_fit_demo", image_tags=["1.2.0"])
docker_image(name="arcor2_upload_fit_demo", repository="arcor2/arcor2_upload_fit_demo", image_tags=["1.3.0"])
6 changes: 6 additions & 0 deletions src/python/arcor2_fit_demo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [1.3.0] - 2024-03-22

### Added

- New ObjectTypes for simulated operations.

## [1.2.0] - 2023-07-20

### Changed
Expand Down
2 changes: 1 addition & 1 deletion src/python/arcor2_fit_demo/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.3.0
23 changes: 23 additions & 0 deletions src/python/arcor2_fit_demo/object_types/erp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import time

from arcor2.data.common import ActionMetadata
from arcor2.object_types.abstract import Generic


class Erp(Generic):
"""ObjectType that simulates Enterprise Resource Planning system."""

_ABSTRACT = False

def log_production_step(self, step: str, success: bool, *, an: None | str = None) -> None:
"""Logs finished production step.
:param step: Name of the production step.
:param success: Indicates whether the step was successful.
:param an:
:return:
"""

time.sleep(0.01)

log_production_step.__action__ = ActionMetadata() # type: ignore
26 changes: 26 additions & 0 deletions src/python/arcor2_fit_demo/object_types/milling_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import random
import time

from arcor2.data.common import ActionMetadata
from arcor2.object_types.abstract import CollisionObject


class MillingMachine(CollisionObject):
_ABSTRACT = False

def do_milling(self, *, an: None | str = None) -> bool:
"""Performs a (simulated) milling process. Returns False if something
goes wrong.
:param an:
:return:
"""

if random.uniform(0, 1) > 0.3:
time.sleep(3)
return True
else:
time.sleep(5)
return False

do_milling.__action__ = ActionMetadata() # type: ignore
23 changes: 23 additions & 0 deletions src/python/arcor2_fit_demo/object_types/optical_quality_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import random
import time

from arcor2.data.common import ActionMetadata
from arcor2.object_types.abstract import CollisionObject


class OpticalQualityControl(CollisionObject):
mesh_filename = "kinect_azure.dae"
_ABSTRACT = False

def measure_quality(self, *, an: None | str = None) -> bool:
"""Performs a (simulated) quality measurement. Returns False if
something is wrong.
:param an:
:return:
"""

time.sleep(0.01)
return random.uniform(0, 1) > 0.3

measure_quality.__action__ = ActionMetadata() # type: ignore
13 changes: 12 additions & 1 deletion src/python/arcor2_fit_demo/scripts/upload_objects.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env python3

from arcor2.data.object_type import Mesh
from arcor2.data.object_type import Box, Mesh
from arcor2.object_types.upload import Urdf, upload_def, upload_whatever
from arcor2_fit_demo import get_data
from arcor2_fit_demo.object_types.abstract_dobot import AbstractDobot
from arcor2_fit_demo.object_types.conveyor_belt import ConveyorBelt
from arcor2_fit_demo.object_types.dobot_m1 import DobotM1
from arcor2_fit_demo.object_types.dobot_magician import DobotMagician
from arcor2_fit_demo.object_types.erp import Erp
from arcor2_fit_demo.object_types.fit_common_mixin import FitCommonMixin
from arcor2_fit_demo.object_types.milling_machine import MillingMachine
from arcor2_fit_demo.object_types.optical_quality_control import OpticalQualityControl
from arcor2_kinect_azure_data.object_types.kinect_azure import KinectAzure


Expand All @@ -27,6 +30,14 @@ def main() -> None:
)
upload_whatever(FitCommonMixin)

upload_def(Erp)
upload_def(MillingMachine, Box(MillingMachine.__name__, 0.1, 0.1, 0.1))
upload_def(
OpticalQualityControl,
Mesh(OpticalQualityControl.__name__, OpticalQualityControl.mesh_filename),
file_to_upload=get_data(OpticalQualityControl.mesh_filename),
)


if __name__ == "__main__":
main()

0 comments on commit 335697b

Please sign in to comment.