Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various minor fixes #140

Merged
merged 9 commits into from
Nov 14, 2024
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Command and Real-time Acquisition in Parallelized PYthon (CRAPPY)
=================================================================

[![Downloads](https://pepy.tech/badge/crappy)](https://pepy.tech/project/crappy)
[![Documentation Status](https://readthedocs.org/projects/crappy/badge/?version=latest)](https://crappy.readthedocs.io/en/latest/?badge=latest)
[![Downloads](https://static.pepy.tech/badge/crappy)](https://www.pepy.tech/projects/crappy)
[![Documentation Status](https://readthedocs.org/projects/crappy/badge/?version=latest)](https://crappy.readthedocs.io/en/latest/)
[![PyPi version](https://badgen.net/pypi/v/crappy/)](https://pypi.org/project/crappy/)
[![Python version](https://img.shields.io/pypi/pyversions/crappy.svg)](https://pypi.org/project/crappy/)

Expand Down
2 changes: 1 addition & 1 deletion docs/source/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ This Barrier is shared by all the Blocks, and its value is set to the number of
Blocks +1. Therefore, the Barrier only breaks when all the Blocks have reached
it, as well as the ``__main__`` Process. In case one of the Processes doesn't
make it to the Barrier, a :obj:`~threading.BrokenBarrierError` is raised to
indicate all the other Blocks not to wait forever on the Barrier.
indicate all the other Blocks not to wait forever at the Barrier.

Once every Process has reached the Barrier, it breaks and releases them all.
At that moment, the :obj:`~multiprocessing.Value` storing the initial timestamp
Expand Down
60 changes: 30 additions & 30 deletions docs/source/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Hardware control
provided with Crappy. This Block can start or stop the script on the
microcontroller, send commands, and receive data.

The examples folder on GitHub contains `on example of the UController Block
The examples folder on GitHub contains `one example of the UController Block
<https://github.com/LaboratoireMecaniqueLille/crappy/tree/master/examples/
blocks/ucontroller>`_.

Expand All @@ -342,6 +342,32 @@ Test management
<https://github.com/LaboratoireMecaniqueLille/crappy/blob/master/examples/
blocks/pause_block.py>`_.

- :ref:`Stop Block`

Stops the current Crappy script if the received data meets one of the given
criteria. One of the clean ways to stop a script in Crappy.

The examples folder on GitHub contains `one example of the Stop Block
<https://github.com/LaboratoireMecaniqueLille/crappy/blob/master/examples/
blocks/stop_block.py>`_.

Refer to the :ref:`dedicated tutorial section
<3. Properly stopping a script>` to learn more about how to properly stop a
script in Crappy.

- :ref:`Stop Button`

Stops the current Crappy script when the user clicks on a button in a GUI.
One of the clean ways to stop a script in Crappy.

The examples folder on GitHub contains `one example of the Stop Button Block
<https://github.com/LaboratoireMecaniqueLille/crappy/blob/master/examples/
blocks/stop_button.py>`_.

Refer to the :ref:`dedicated tutorial section
<3. Properly stopping a script>` to learn more about how to properly stop a
script in Crappy.

Others
++++++

Expand All @@ -352,7 +378,7 @@ Others
communicating with distant devices over a network, e.g. for remotely
controlling a test.

The examples folder on GitHub contains `on example of the Client Server Block
The examples folder on GitHub contains `one example of the ClientServer Block
<https://github.com/LaboratoireMecaniqueLille/crappy/tree/master/examples/
blocks/client_server>`_.

Expand All @@ -363,44 +389,18 @@ Others
examples because it doesn't require any hardware, but may as well be used for
debugging or prototyping.

The examples folder on GitHub contains `on example of the Fake Machine Block
The examples folder on GitHub contains `one example of the Fake Machine Block
<https://github.com/LaboratoireMecaniqueLille/crappy/blob/master/examples/
blocks/fake_machine.py>`_.

- :ref:`Sink`

Discards any received data. Used for prototyping and debugging only.

The examples folder on GitHub contains `on example of the Sink Block
The examples folder on GitHub contains `one example of the Sink Block
<https://github.com/LaboratoireMecaniqueLille/crappy/blob/master/examples/
blocks/sink.py>`_.

- :ref:`Stop Block`

Stops the current Crappy script if the received data meets one of the given
criteria. One of the clean ways to stop a script in Crappy.

The examples folder on GitHub contains `on example of the Stop Block
<https://github.com/LaboratoireMecaniqueLille/crappy/blob/master/examples/
blocks/stop_block.py>`_.

Refer to the :ref:`dedicated tutorial section
<3. Properly stopping a script>` to learn more about how to properly stop a
script in Crappy.

- :ref:`Stop Button`

Stops the current Crappy script when the user clicks on a button in a GUI.
One of the clean ways to stop a script in Crappy.

The examples folder on GitHub contains `on example of the Stop Button Block
<https://github.com/LaboratoireMecaniqueLille/crappy/blob/master/examples/
blocks/stop_button.py>`_.

Refer to the :ref:`dedicated tutorial section
<3. Properly stopping a script>` to learn more about how to properly stop a
script in Crappy.

Supported hardware (Cameras, InOuts, Actuators)
-----------------------------------------------

Expand Down
8 changes: 4 additions & 4 deletions src/crappy/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

from .auto_drive_video_extenso import AutoDriveVideoExtenso
from .meta_block import Block
from .button import Button
from .camera import Camera
from .canvas import Canvas
from .client_server import ClientServer
from .dashboard import Dashboard
from .dis_correl import DISCorrel
from .dic_ve import DICVE
from .canvas import Canvas
from .dis_correl import DISCorrel
from .fake_machine import FakeMachine
from .generator import Generator
from .gpu_correl import GPUCorrel
from .gpu_ve import GPUVE
from .grapher import Grapher
from .button import Button
from .hdf_recorder import HDFRecorder
from .ioblock import IOBlock
from .link_reader import LinkReader
from .machine import Machine
from .mean import MeanBlock
from .multiplexer import Multiplexer
from .pause import Pause
from .pid import PID
from .link_reader import LinkReader
from .recorder import Recorder
from .sink import Sink
from .stop_block import StopBlock
Expand Down
11 changes: 6 additions & 5 deletions src/crappy/blocks/meta_block/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def __init__(self) -> None:
# Various objects that should be set by child classes
self.niceness: int = 0
self.labels: Optional[Iterable[str]] = None
self.freq = None
self.display_freq = False
self.name = self.get_name(type(self).__name__)
self.freq: Optional[float] = None
self.display_freq: bool = False
self.name: str = self.get_name(type(self).__name__)
self.pausable: bool = True

# The synchronization objects will be set later
Expand Down Expand Up @@ -969,7 +969,7 @@ def prepare(self) -> None:
Block before the test starts.

For example, it can open a network connection, create a file, etc. It is
also fine for this method not to be overriden if there's no particular
also fine for this method not to be overridden if there's no particular
action to perform.

Note that this method is called once the :obj:`~multiprocessing.Process`
Expand Down Expand Up @@ -1055,8 +1055,9 @@ def _handle_freq(self) -> None:

# Correcting the error of the sleep function through a recursive approach
# The last 2 milliseconds are in free loop
while (remaining := self._last_t + 1 / self.freq - t) > 0:
while self._last_t + 1 / self.freq - t > 0:
t = time_ns() / 1e9
remaining = self._last_t + 1 / self.freq - t
sleep(max(0., remaining / 2 - 2e-3))

self._last_t = t
Expand Down
14 changes: 7 additions & 7 deletions src/crappy/blocks/stop_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def __init__(self,
"""Sets the arguments and initialize the parent class.

Args:
criteria: A :obj:`str`, a :obj:`~typing.Callable`, or an
:obj:`~typing.Iterable` (like a :obj:`tuple` or a :obj:`list`)
containing such objects. Each :obj:`str` or :obj:`~typing.Callable`
represents one stop criterion. There is no limit to the given number of
stop criteria. If a criterion is given as an :obj:`~typing.Callable`,
it should accept as its sole argument the output of the
criteria: A :obj:`str`, a :obj:`~collections.abc.Callable`, or an
:obj:`~collections.abc.Iterable` (like a :obj:`tuple` or a :obj:`list`)
containing such objects. Each :obj:`str` or
:obj:`~collections.abc.Callable` represents one stop criterion. There
is no limit to the given number of stop criteria. If a criterion is
given as an :obj:`~collections.abc.Callable`, it should accept as its
sole argument the output of the
:meth:`crappy.blocks.Block.recv_all_data` method and return :obj:`True`
if the criterion is met, and :obj:`False` otherwise. If the criterion
is given as a :obj:`str`, it should follow the following syntax :
Expand Down Expand Up @@ -150,4 +151,3 @@ def cond(data: dict[str, list]) -> bool:
else:
raise ValueError("Wrong syntax for the criterion, please refer to the "
"documentation")

2 changes: 1 addition & 1 deletion src/crappy/inout/phidgets_wheatstone_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def open(self) -> None:
self.log(logging.DEBUG, "Trying to attach the load cell conditioner")
self._load_cell.openWaitForAttachment(10000)
except PhidgetException:
raise TimeoutError("Waited too long for the motor to attach !")
raise TimeoutError("Waited too long for the bridge to attach !")

def get_data(self) -> Optional[list[float]]:
"""Returns the last known voltage ratio value, adjusted with the gain and
Expand Down
1 change: 0 additions & 1 deletion src/crappy/tool/camera_config/camera_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import tkinter as tk
from tkinter.messagebox import showerror
from _tkinter import TclError
from platform import system
import numpy as np
from time import time, sleep
Expand Down