Skip to content

Commit

Permalink
Merge pull request #67 from LaboratoireMecaniqueLille/v1.5.11
Browse files Browse the repository at this point in the history
Release of version 1.5.11
  • Loading branch information
WeisLeDocto authored Nov 5, 2023
2 parents 004be56 + b74e9c1 commit 95ca19e
Show file tree
Hide file tree
Showing 115 changed files with 915 additions and 32 deletions.
6 changes: 1 addition & 5 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/source/conf.py

# Optionally set the version of Python and requirements required to build your docs
build:
os: ubuntu-22.04
Expand All @@ -22,6 +18,6 @@ sphinx:

python:
install:
- requirements: requirements.txt
- requirements: docs/source/requirements.txt
- method: pip
path: .
4 changes: 1 addition & 3 deletions Examples/correl_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@
'uxx', 'uyy', 'uxy', # Quadratic def (x)
'vxx', 'vyy', 'vxy'], # Quadratic def (y)
verbose=2, # To print info
show_diff=True, # Display the residual
# (slow!)
drop=False, # Disable data picker
mask=mask,
levels=4, # Reduce the number of levels
iterations=3, # and of iteration
resampling_factor=2.5, # aggressive
# resampling
labels=[ # Needed to name our custom field
't(s)', 'meta',
'x', 'y', 'r', 'Exx', 'Eyy', 'Exy',
'Ux2', 'Uy2', 'Uxy',
'Vx2', 'Vy2', 'Vxy'],
Expand Down
4 changes: 2 additions & 2 deletions Examples/correl_fake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def __call__(self, exx: float, eyy: float) -> np.ndarray:

# The block performing the DIC
dis = crappy.blocks.DISCorrel('', show_image=True,
labels=['t(s)', 'x', 'y', 'measured_Exx(%)',
'measured_Eyy(%)'],
labels=['t(s)', 'meta', 'x', 'y',
'measured_Exx(%)', 'measured_Eyy(%)'],
image_generator=Apply_strain_img(img),
verbose=True, display_images=True)
# This modifier will generate an image with the values of strain
Expand Down
4 changes: 2 additions & 2 deletions Examples/correl_strain_controlled_fake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def __call__(self, exx: float, eyy: float) -> np.ndarray:

# The block performing the DIC
dis = crappy.blocks.DISCorrel('', display_images=True,
labels=['t(s)', 'x', 'y', 'measured_Exx(%)',
'measured_Eyy(%)'],
labels=['t(s)', 'meta', 'x', 'y',
'measured_Exx(%)', 'measured_Eyy(%)'],
verbose=True, iterations=0, finest_scale=2,
image_generator=Apply_strain_img(img))

Expand Down
10 changes: 6 additions & 4 deletions Examples/dio_daqmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def change_name(data, prev: str, new: str):
gen = crappy.blocks.Generator([dict(type='cyclic', value1=0, value2=1,
condition1="delay=1",
condition2="delay=1")], repeat=True)
io = crappy.blocks.IOBlock("Nidaqmx", device="Dev2",
channels=[dict(name='ai0'), dict(name='di0'),
dict(name='ao0'), dict(name='do1')],
samplerate=100,
io = crappy.blocks.IOBlock("Nidaqmx",
channels=[dict(name='Dev2/ai0'),
dict(name='Dev2/di0'),
dict(name='Dev2/ao0'),
dict(name='Dev2/do1')],
sample_rate=100,
labels=['t(s)', 'ai0', 'di0'],
cmd_labels=['cmd', 'cmd2'])
crappy.link(gen, io)
Expand Down
2 changes: 1 addition & 1 deletion Examples/discorrel_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if __name__ == "__main__":
dis = crappy.blocks.DISCorrel('Webcam',
fields=['x', 'y'],
labels=['t(s)', 'x(pix)', 'y(pix)'],
labels=['t(s)', 'meta', 'x(pix)', 'y(pix)'],
display_images=True)

graph = crappy.blocks.Grapher(('x(pix)', 'y(pix)'))
Expand Down
4 changes: 2 additions & 2 deletions Examples/gpucorrel_fake_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def __call__(self, exx: float, eyy: float) -> np.ndarray:

# The block performing the DIC
dis = crappy.blocks.GPUCorrel('', verbose=True,
labels=['t(s)', 'x', 'y', 'measured_Exx(%)',
'measured_Eyy(%)'],
labels=['t(s)', 'meta', 'x', 'y',
'measured_Exx(%)', 'measured_Eyy(%)'],
fields=['x', 'y', 'exx', 'eyy'], levels=3,
image_generator=Apply_strain_img(img))
# This modifier will generate an image with the values of strain
Expand Down
2 changes: 1 addition & 1 deletion Examples/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
cmd_label='cmd')

io = crappy.blocks.IOBlock(name, labels=['t(s)', 'chan0'],
cmd_labels=['cmd'], out_channels=0, verbose=True)
cmd_labels=['cmd'], verbose=True)
crappy.link(sg, io)

g = crappy.blocks.Grapher(('t(s)', 'chan0'))
Expand Down
1 change: 1 addition & 0 deletions Examples/tensile_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"type": "ramp",
"speed": SPEED / 60, # Convert to mm/s (in ramps, speed is always
# in unit/s)
'init_value': 0,
"condition": None} # No exit condition: we will stop the test manually

# Let's create the first block: the generator
Expand Down
2 changes: 1 addition & 1 deletion Examples/thermocouple_daqmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
type='thrmcpl',
thermocouple_type='K')
for c_name in chan_names],
samplerate=14. / len(channels),
sample_rate=14. / len(channels),
labels=['t(s)', 'stream'] if STREAMER else labels,
streamer=STREAMER)

Expand Down
8 changes: 8 additions & 0 deletions crappy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from numpy import frombuffer, uint8
from ._global import OptionalModule
from webbrowser import open
from warnings import warn

from . import actuator
from . import camera
Expand All @@ -17,9 +18,16 @@
# For compatibility (deprecated!)
condition = modifier

warn("Version 1.5.11 of Crappy is the last one before 2.0.0, that will "
"contain many breaking changes.\nThe warnings displayed in the terminal "
"should help you identify how to modify your scripts when upgrading to "
"2.0.0.", FutureWarning)


# Quick access to documentation
def doc():
warn("The doc function will be renamed to docs in version 2.0.0",
FutureWarning)
open('https://crappy.readthedocs.io/en/latest/')


Expand Down
2 changes: 1 addition & 1 deletion crappy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# coding: utf-8

__version__ = '1.5.10'
__version__ = '1.5.11'
8 changes: 7 additions & 1 deletion crappy/_global.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# coding:utf-8

from warnings import warn


class OptionalModule:
"""Placeholder for optional dependencies when not installed
Expand Down Expand Up @@ -28,7 +31,10 @@ def __call__(self, *_, **__):
class CrappyStop(Exception):
"""Error to raise when Crappy is terminating"""

pass
def __init__(self):
warn("The CrappyStop Exception will be removed in version 2.0.0",
DeprecationWarning)
super().__init__()


class DefinitionError(Exception):
Expand Down
4 changes: 4 additions & 0 deletions crappy/actuator/actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from time import sleep
from typing import Optional
from warnings import warn

from .._global import DefinitionError

Expand Down Expand Up @@ -64,6 +65,9 @@ def set_position(self,
position. A speed value can optionally be provided for specifying the speed
at which the actuator should move for getting to the desired position."""

warn("The speed argument of set_position will not be optional anymore in "
"version 2.0.0, and will be None if no speed is set", FutureWarning)

print(f"WARNING ! Trying to drive the Actuator {type(self).__name__} in "
f"position but it does not define a set_position method !\n"
f"No command sent to the actuator.")
Expand Down
17 changes: 17 additions & 0 deletions crappy/actuator/biotens.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from struct import pack, unpack
from typing import Union, Optional
import time
from warnings import warn
from .actuator import Actuator
from .._global import OptionalModule

Expand Down Expand Up @@ -58,6 +59,10 @@ def __init__(self,
baudrate (:obj:`int`, optional): Set the corresponding baud rate.
"""

if baudrate != 19200:
warn("The baudrate argument will be removed in version 2.0.0",
FutureWarning)

Actuator.__init__(self)
self.port = port
self.baudrate = baudrate
Expand Down Expand Up @@ -134,6 +139,8 @@ def reset_position(self) -> None:
def reset(self) -> None:
""""""

warn("The reset method will be removed in version 2.0.0", FutureWarning)

pass

def stop(self) -> None:
Expand All @@ -155,6 +162,9 @@ def close(self) -> None:
def clear_errors(self) -> None:
"""Clears error in motor registers."""

warn("The clear_errors method will be removed in version 2.0.0",
FutureWarning)

command = b'\x52\x52\x52\xFF\x00' +\
convert_to_byte(35, 'B') +\
convert_to_byte(4, 'B') +\
Expand Down Expand Up @@ -214,6 +224,9 @@ def set_position(self,
"""Pilot in position mode, needs speed and final position to run
(in `mm/min` and `mm`)."""

warn("The speed argument of set_position will not be optional anymore in "
"version 2.0.0, and will be None if no speed is set", FutureWarning)

if speed is None:
raise ValueError("The Biotens actuator needs both a position and a speed"
" command when driven in position mode !")
Expand Down Expand Up @@ -287,6 +300,10 @@ def get_position(self) -> float:
raise IOError("Could not read biotens pos!")

def _get_position(self) -> Union[float, None]:

warn("The _get_position method will be removed in version 2.0.0",
DeprecationWarning)

try:
self.ser.readlines()
except serial.SerialException:
Expand Down
16 changes: 16 additions & 0 deletions crappy/actuator/cmDrive.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8

from typing import Optional
from warnings import warn

from .actuator import Actuator
from .._global import OptionalModule
Expand All @@ -23,6 +24,9 @@ def __init__(self, port: str = '/dev/ttyUSB0', baudrate: int = 9600) -> None:
baudrate (:obj:`int`, optional): Set the corresponding baud rate.
"""

warn("The CM_drive Actuator will be renamed to SchneiderMDrive23 in "
"version 2.0.0", FutureWarning)

Actuator.__init__(self)
self.port = port
self.baudrate = baudrate
Expand Down Expand Up @@ -75,6 +79,9 @@ def close(self) -> None:
def clear_errors(self) -> None:
"""Reset errors."""

warn("The clear_errors method will be removed in version 2.0.0",
FutureWarning)

self.ser.write("CLRFAULT\r\n")
self.ser.write("OPMODE 0\r\n EN\r\n")

Expand All @@ -99,6 +106,12 @@ def set_position(self,
"""Pilot in position mode, needs speed and final position to run
(in `mm/min` and `mm`)."""

warn("The speed argument of set_position will not be optional anymore in "
"version 2.0.0, and will be None if no speed is set", FutureWarning)

warn("The motion_type argument of set_position will be removed in version "
"2.0.0 ", FutureWarning)

self.ser.close() # close serial connection before to avoid errors
self.ser.open() # open serial port

Expand All @@ -114,6 +127,9 @@ def set_position(self,
def move_home(self) -> None:
"""Reset the position to zero."""

warn("The move_home method will be removed in version 2.0.0",
FutureWarning)

self.ser.open() # open serial port
# send 'MH' ASCII characters for requesting to the motor to return at pos 0
self.ser.write('MA 0\r')
Expand Down
11 changes: 11 additions & 0 deletions crappy/actuator/fakemotor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8

from time import time
from warnings import warn

from .actuator import Actuator

Expand Down Expand Up @@ -38,6 +39,13 @@ def __init__(self,
initial_pos(:obj:`float`, optional): (turns)
"""

warn("The Fake_motor Actuator will be renamed to FakeDCMotor in version "
"2.0.0", FutureWarning)

if sim_speed != 1:
warn("The sim_speed argument will be renamed to simulation_speed in "
"version 2.0.0", FutureWarning)

super().__init__()
self.inertia = inertia
self.torque = torque
Expand Down Expand Up @@ -68,6 +76,9 @@ def update(self) -> None:
Supposes `u` is constant for the interval `dt`.
"""

warn("The update method will be renamed to _update in version 2.0.0",
FutureWarning)

t1 = time() * self.sim_speed
dt = (t1 - self.t)
self.t = t1
Expand Down
10 changes: 10 additions & 0 deletions crappy/actuator/motorkit_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from struct import pack_into
from time import sleep
from typing import Union
from warnings import warn
from .actuator import Actuator
from .._global import OptionalModule
from ..tool import ft232h_server as ft232h, Usb_server
Expand Down Expand Up @@ -81,6 +82,9 @@ def __init__(self,
board.
"""

warn("The DC_motor_hat class will be removed in version 2.0.0",
FutureWarning)

if not all(i in range(1, 5) for i in motor_nrs):
raise ValueError("The DC motor hat can only drive up to 4 DC motors at "
"a time !")
Expand Down Expand Up @@ -201,6 +205,12 @@ def __init__(self,
serial number of the ft232h to use for communication.
"""

warn("The Motorkit_pump Actuator will be renamed to DCMotorHat in version "
"2.0.0", FutureWarning)
if ft232h_ser_num is not None:
warn("The ft232h_ser_num argument of the Motorkit_pump Actuator will be "
"removed in version 2.0.0")

if not isinstance(backend, str) or backend not in motor_hat_backends:
raise ValueError("backend should be in {}".format(motor_hat_backends))
self._backend = backend
Expand Down
Loading

0 comments on commit 95ca19e

Please sign in to comment.