Ejemplo n.º 1
0
 def test_create_variables(self):
     variables = create_variables(var_dict)
     print(variables["air_temp"].name)
     assert isinstance(variables["air_temp"], VariableInfo)
     assert isinstance(variables["air_press"], VariableInfo)
     assert variables["air_temp"].name == "air_temp"
     assert variables["air_temp"].__doc__ == var_dict["air_temp"]["description"]
     assert variables["air_temp"].units == var_dict["air_temp"]["units"]
Ejemplo n.º 2
0
import requests
from PIL import Image
from couchdb import Server
from StringIO import StringIO
from sensor_msgs.msg import Image as ImageMsg
from re import match

from openag.cli.config import config as cli_config
from openag.models import EnvironmentalDataPoint, SoftwareModule
from openag.db_names import ENVIRONMENTAL_DATA_POINT, SOFTWARE_MODULE
from openag_brain.load_env_var_types import create_variables
from openag_brain import params
from openag_brain.utils import read_environment_from_ns

# Filter a list of environmental variables that are specific to camera
CAMERA_VARIABLES = create_variables(rospy.get_param('/var_types/camera_variables'))

class ImagePersistence:
    image_format_mapping = {
        "rgb8": "RGB",
        "rgba8": "RGBA"
    }

    def __init__(self, db, topic, variable, environment, min_update_interval):
        self.db = db
        self.variable = variable
        self.environment = environment
        self.min_update_interval = min_update_interval
        self.last_update = 0
        self.sub = rospy.Subscriber(topic, ImageMsg, self.on_image)
Ejemplo n.º 3
0
#!/usr/bin/python
import rospy

from std_msgs.msg import Float64
from openag_brain.load_env_var_types import create_variables
from openag_brain.constants import SENTINELS

# Filter a list of environmental variables that are specific to environment
# sensors and actuators
ENVIRONMENT_VARIABLES = create_variables(rospy.get_param('/var_types/environment_variables'))

class EWMA:
    """
    Calculate the Exponentially Weighted Moving Average (EWMA) for an input variable.
    EWMAi = alpha * Xi + (1 - alpha) * EWMAi-1
    Params:
        a : Alpha is the dapening coefficient. The lower the value the less damped. Should be between 0 and 1
    """
    def __init__(self, a):
        self.a = a
        self.average = None

    def __call__(self, sample):
        # Update the average
        if self.average is None:
            self.average = sample
            return
        self.average = self.a * sample + (1 - self.a) * self.average


def filter_topic(src_topic, dest_topic, topic_type):
Ejemplo n.º 4
0
"""
Stitches together the images from a recipe run and stores them as a video on
the recipe_start data point
"""
import os
import rospy
import tempfile
import threading
import subprocess
from openag.cli.config import config as cli_config
from openag.couch import Server
from openag.db_names import ENVIRONMENTAL_DATA_POINT
from openag_brain.video_helpers import *
from openag_brain.load_env_var_types import create_variables
# Filter a list of environmental variables that are specific to camera
CAMERA_VARIABLES = create_variables(
    rospy.get_param('/var_types/camera_variables'))
RECIPE_START, RECIPE_END = create_variables(
    rospy.get_param('/var_types/recipe_variables'))

IMAGE_ATTACHMENT = "image"
TIMELAPSE_ATTACHMENT = "timelapse"

IMAGE_FILENAME = "image.png"
WORKING_TIMELAPSE_FILENAME = "timelapse.mpeg"
TIMELAPSE_FILENAME = "timelapse.mp4"
SNIPPET_FILENAME = "snippet.mpeg"

# By default, each second of the timelapse will correspond to 1 day in real
# time
DEFAULT_TIMELAPSE_SCALING_FACTOR = 24 * 60 * 60
Ejemplo n.º 5
0
#!/usr/bin/python
import rospy

from std_msgs.msg import Float64
from openag_brain.load_env_var_types import create_variables
from openag_brain.constants import SENTINELS

# Filter a list of environmental variables that are specific to environment
# sensors and actuators
ENVIRONMENT_VARIABLES = create_variables(
    rospy.get_param('/var_types/environment_variables'))


class EWMA:
    """
    Calculate the Exponentially Weighted Moving Average (EWMA) for an input variable.
    EWMAi = alpha * Xi + (1 - alpha) * EWMAi-1
    Params:
        a : Alpha is the dapening coefficient. The lower the value the less damped. Should be between 0 and 1
    """
    def __init__(self, a):
        self.a = a
        self.average = None

    def __call__(self, sample):
        # Update the average
        if self.average is None:
            self.average = sample
            return
        self.average = self.a * sample + (1 - self.a) * self.average
Ejemplo n.º 6
0
the recipe_start data point
"""
import os
import rospy
import tempfile
import threading
import subprocess

from couchdb import Server
from openag_lib.config import config as cli_config
from openag_lib.db_bootstrap.db_names import ENVIRONMENTAL_DATA_POINT
from openag_brain.video_helpers import *
from openag_brain.load_env_var_types import create_variables, VariableInfo

# Filter a list of environmental variables that are specific to camera
CAMERA_VARIABLES = create_variables(
    rospy.get_param('/var_types/camera_variables'))
RECIPE_START = VariableInfo.from_dict(
    rospy.get_param('/var_types/recipe_variables/recipe_start'))
RECIPE_END = VariableInfo.from_dict(
    rospy.get_param('/var_types/recipe_variables/recipe_end'))
IMAGE_ATTACHMENT = "image"
TIMELAPSE_ATTACHMENT = "timelapse"

IMAGE_FILENAME = "image.png"
WORKING_TIMELAPSE_FILENAME = "timelapse.mpeg"
TIMELAPSE_FILENAME = "timelapse.mp4"
SNIPPET_FILENAME = "snippet.mpeg"

# By default, each second of the timelapse will correspond to 1 day in real
# time
DEFAULT_TIMELAPSE_SCALING_FACTOR = 24*60*60
Ejemplo n.º 7
0
from openag.models import EnvironmentalDataPoint
from couchdb import Server
from std_msgs.msg import Float64
from threading import RLock
from openag_brain import params, services
from openag_brain.srv import StartRecipe, Empty
from openag_brain.utils import gen_doc_id, read_environment_from_ns
from openag_brain.memoize import memoize
from openag_brain.multidispatch import multidispatch

from openag_brain.load_env_var_types import create_variables

# Create a tuple constant of valid environmental variables
# Should these be only environment_variables?
VALID_VARIABLES = frozenset(
    create_variables(rospy.get_param('/var_types/environment_variables')))

# Need to check if the correct order is maintained?
RECIPE_START, RECIPE_END = create_variables(
    rospy.get_param('/var_types/recipe_variables'))


@memoize
def publisher_memo(topic, MsgType, queue_size):
    """
    A memoized publisher function which will return a cached publisher
    instance for the same topic, type and queue_size.
    """
    return rospy.Publisher(topic, MsgType, queue_size=queue_size)