예제 #1
0
 def test_to_yaml(self):
     # p = Port(); self.c.add_interface("AnInterface",p)
     self.c.add_parameter("Width", 79)
     self.c.to_yaml("testfile")
     c2 = Component()
     c2.from_yaml("testfile")
     self.assertEqual(c2.get_parameter("Width"), 79)
예제 #2
0
def get_component(c, **kwargs):
    # import pdb; pdb.set_trace()
    try:
        mod = __import__(c, fromlist=[c, "library." + c], globals=globals())
        obj = getattr(mod, to_camel_case(c))()
    except AttributeError:
        try:
            obj = getattr(mod, c)()
        except AttributeError:
            obj = Component(
                os.path.abspath(os.path.dirname(__file__)) + "/" + c + ".yaml")
    except ImportError:
        if "baseclass" in kwargs:
            bc = try_import(kwargs["baseclass"], kwargs["baseclass"])
            obj = bc(
                os.path.abspath(os.path.dirname(__file__)) + "/" + c + ".yaml")
        else:
            obj = Component(
                os.path.abspath(os.path.dirname(__file__)) + "/" + c + ".yaml")

    for k, v in kwargs.iteritems():
        if k == 'name':
            obj.set_name(v)
        elif k == 'baseclass':
            pass
        else:
            obj.set_parameter(k, v)

    if 'name' not in kwargs:
        obj.set_name(c)

    return obj
예제 #3
0
    def __init__(self, yaml_file=None, name=None, **kwargs):
        """Initializes an empty Code Component if yaml_file is None, or a
        composite code component if yaml_file is a valid Composite Component File.

        Args:
            yaml_file (string): Path to a YAML file that contains the structure
                                for a composite component.
            **kwargs: Arbitrary keyword arguments to control construction.


        """
        Component.__init__(self, yaml_file=None, name=name, **kwargs)
예제 #4
0
 def __init__(self, yaml_file=None, **kwargs):
     Component.__init__(self, yaml_file, **kwargs)
예제 #5
0
from roco.api.component import Component
from roco.library import *

if __name__ == "__main__":
    c = Component(name="Andruino")
    c.add_subcomponent("srl","serial_in")
    c.add_subcomponent("S2S","serial_to_string")
    c.add_subcomponent("S2M","string_to_motor")
    c.add_connection(("srl","received"),("S2S","received"))
    c.add_connection(("srl","came"),("S2S","came"))
    c.add_connection(("S2S","receivedString"),("S2M","motorString"))
    c.add_connection(("S2S","cameOut"),("S2M","motorCame"))
    c.make_output()
예제 #6
0
from roco.library.pot import Pot
from roco.api.component import Component
from roco.library.pot_driver import PotDriver

if __name__ == "__main__":
    c = Component(name = "DrivenPot")
    c.add_subcomponent("pot", "pot")
    c.add_subcomponent("dPot", "pot_driver")
    c.add_connection(("pot", "vOut"), ("dPot", "vIn"))
    c.inherit_interface("aOut", ("dPot", "aOut"))
    c.inherit_interface("outInt", ("dPot", "outInt"))
    c.make_output()
예제 #7
0
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

if __name__ == "__main__":
    c = Component(name='ArduinoCode')
    c.add_subcomponent('serial_in0', 'serial_in')
    c.add_subcomponent('serial_to_string0', 'serial_to_string')
    c.add_subcomponent('string_compare0', 'string_compare')
    c.add_connection(('', 'ial_in0->received'),
                     ('serial_to_string0', 'received'))
    c.add_connection(('', 'ial_in0->came'), ('serial_to_string0', 'came'))
    c.add_connection(('', 'ial_to_string0->cameOut'),
                     ('string_compare0', 'inDetected'))
    c.add_connection(('', 'ial_to_string0->receivedString'),
                     ('string_compare0', 'inString'))
    c.to_yaml("library/ArduinoCode.yaml")
예제 #8
0
from roco.api.component import Component
from roco.library import *

if __name__ == "__main__":
    c = Component(name="serial")
    c.add_subcomponent("srl", "serial_in")
    c.make_output()
예제 #9
0
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

if __name__ == "__main__":
    c = Component(name='Roco_andruino')
    c.add_subcomponent('serial', 'serial_in')
    c.add_subcomponent('s2s', 'serial_to_string')
    c.add_subcomponent('checker', 'string_compare')
    c.add_connection(('serial', 'received'), ('s2s', 'received'))
    c.add_connection(('serial', 'came'), ('s2s', 'came'))
    c.add_connection(('s2s', 'cameOut'), ('checker', 'inDetected'))
    c.add_connection(('s2s', 'receivedString'), ('checker', 'inString'))
    c.make_output()
예제 #10
0
class TestComponent(unittest.TestCase):
    def setUp(self):
        self.c = Component()
        # Creates a single set-up code for all test cases that need an instance of Component
        # It is called for every single test case

    def test_add_connection(self):
        self.assertRaises(Exception, self.c.add_connection,
                          (from_subcomponent, from_interface),
                          (to_subcomponent, to_interface))
        # Assuming there should be an error if since the subcomponents have not been defined yet

    def test_add_interface_valueerror(self):
        self.assertRaises(ValueError, self.p.add_interface, "invalid_name",
                          Port())
        # A ValueError should be raised because the name cannot have underscores
        # Are there any other invalid characters?

    def test_get_interface(self):
        p = Port()
        self.c.add_interface("AnInterface", p)
        self.assertEqual(self.c.get_interface("AnInterface"),
                         p)  # Is this a correct comparison?

    # Adds an interface, and then checks it

    def test_get_subcomponent(self):
        self.c.add_subcomponent("TestSubcomponent", "Component")
        self.assertEqual(
            isinstance(self.c.get_subcomponent("TestSubcomponent"),
                       Component()), True)

    def test_make(self):
        try:
            self.c.make()
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)

    def test_delete_subcomponent(self):
        self.c.add_subcomponent("TestSubcomponent", "Component")
        try:
            self.c.delete_subcomponent("TestSubcomponent")
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)

    def test_delete_interface(self):
        p = Port()
        self.c.add_interface("AnInterface", p)
        try:
            self.c.delete_interface("AnInterface")
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)

    def test_define(self):
        try:
            self.c.define()
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)

    def test_to_yaml(self):
        # p = Port(); self.c.add_interface("AnInterface",p)
        self.c.add_parameter("Width", 79)
        self.c.to_yaml("testfile")
        c2 = Component()
        c2.from_yaml("testfile")
        self.assertEqual(c2.get_parameter("Width"), 79)

    def test_assemble(self):
        try:
            self.c.assemble()
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)

    def test_make(self):
        try:
            self.c.make()
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)

    def test_reset(self):
        try:
            self.c.reset()
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)

    def test_make_component_tree(self):
        try:
            self.c.make_component_tree("FileName", "TreeName")
            self.assertEqual(True, True)
        except:
            self.assertEqual(True, False)
예제 #11
0
 def test_get_subcomponent(self):
     self.c.add_subcomponent("TestSubcomponent", "Component")
     self.assertEqual(
         isinstance(self.c.get_subcomponent("TestSubcomponent"),
                    Component()), True)
예제 #12
0
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

if __name__ == "__main__":
    c = Component(name='DrivenServo')
    c.add_subcomponent('servo0', 'servo')
    c.add_subcomponent('servo_driver0', 'servo_driver')
    c.add_connection(('servo_driver0', 'eOut'), ('servo0', 'eIn'))
    c.inherit_interface('PWMin', ('servo_driver0', 'PWMin'))
    c.inherit_interface('inInt', ('servo_driver0', 'inInt'))
    c.to_yaml("library/DrivenServo.yaml")
예제 #13
0
import pdb
from roco.api.component import Component
#pdb.set_trace()

if __name__ == "__main__":
    c = Component()
    c.add_subcomponent("1st","Rectangle")
    c.make_output()
예제 #14
0
from roco.library.pot import Pot
from roco.api.component import Component
from roco.library.pot_driver import PotDriver
from roco.library.led import LED
from roco.library.node_mcu import NodeMcu

if __name__ == "__main__":
    c = Component(name="LEDPot")
    c.add_subcomponent("pot", "pot")
    c.add_subcomponent("dPot", "pot_driver")
    c.add_subcomponent("nmcu", "node_mcu")
    c.add_subcomponent("led", "led")
    c.add_connection(("pot", "vOut"), ("dPot", "vIn"))
    c.add_connection(("dPot", "aOut"), ("nmcu", "a1"))
    c.make_output()
예제 #15
0
 def define(self, origin=False, euler=None, quat=False, **kwargs):
     Component.define(self, **kwargs)
     self.transform3D = np.eye(4)
예제 #16
0
 def setUp(self):
     self.c = Component()
예제 #17
0
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

c = Component(name='interface')
c.add_subcomponent('button_one', 'web_button')
c.add_subcomponent('button_two', 'web_button')
c.add_subcomponent('button_three', 'web_button')
c.get_subcomponent('button_one').set_parameter('buttonValue', 'GO')
c.get_subcomponent('button_two').set_parameter('buttonValue', 'BACK')
c.get_subcomponent('button_three').set_parameter('buttonValue', 'STOP')
c.make_output()
예제 #18
0
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

if __name__ == "__main__":
    c = Component(name='GetSerialString')
    c.add_subcomponent('sIn', 'serial_in')
    c.add_subcomponent('s2s', 'serial_to_string')
    c.add_connection(('sIn', 'received'), ('s2s', 'received'))
    c.add_connection(('sIn', 'came'), ('s2s', 'came'))
    c.inherit_interface('out1', ('s2s', 'cameOut'))
    c.inherit_interface('out2', ('s2s', 'receivedString'))
    c.to_yaml("library/getSerialString.yaml")
예제 #19
0
from roco.api.component import Component
from roco.library import *

if __name__ == "__main__":
    c = Component(name="comp")
    c.add_subcomponent("sort", "sort_string")
    c.add_subcomponent("str", "string_source")
    c.add_connection(("str", "outStr"), ("sort", "inStr"))
    c.inherit_interface("out", ("sort", "outStr"))
    c.make_output()
예제 #20
0
from roco.api.component import Component

if __name__ == "__main__":
    c = Component()
    # import pdb
    # pdb.set_trace()
    c.add_subcomponent("r1", "Square")
    c.add_subcomponent("r2", "Square")
    c.add_subcomponent("r3", "Square")
    c.add_subcomponent("r4", "Square")
    c.add_connection(("r1", "r"), ("r2", "l"), angle=90)
    c.add_connection(("r2", "r"), ("r3", "l"), angle=90)
    c.add_connection(("r3", "r"), ("r4", "l"), angle=90)
    c.add_connection(("r4", "r"), ("r1", "l"), angle=90, tab=True)
    c.make_output(thickness=10)

    # def multiplyTwo(c,d):
    #     print("Originally, c is ", c)
    #     print("Originally, d is ", d)
    #     addOne(c)
    #     addOne(d)
    #     print("Now, c is ", c)
    #     print("Now, d is ", d)
    #     return c*d
    #
    # def addOne(x):
    #     return x+1
    #
    # result = multiplyTwo(1,3)
    # print result
예제 #21
0
파일: Roco.py 프로젝트: uclalemur/roco
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

if __name__ == "__main__":
    c = Component(name='Roco')
    c.add_subcomponent('serial', 'serial_in')
    c.add_subcomponent('s2s', 'serial_to_string')
    c.add_subcomponent('compare', 'string_compare')
    c.add_connection(('serial', 'received'), ('s2s', 'received'))
    c.add_connection(('serial', 'came'), ('s2s', 'came'))
    c.add_connection(('s2s', 'cameOut'), ('compare', 'inDetected'))
    c.add_connection(('s2s', 'receivedString'), ('compare', 'inString'))
    c.to_yaml("library/Roco.yaml")
예제 #22
0
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

if __name__ == "__main__":
    c = Component()
    c.to_yaml("library/user_name.yaml")
예제 #23
0
파일: led_pot.py 프로젝트: uclalemur/roco
from roco.library.pot import Pot
from roco.api.component import Component
# from roco.library.pot_driver import PotDriver
from roco.library.led import LED

if __name__ == "__main__":
    c = Component(name="LEDPot")
    c.add_subcomponent("pot", "pot")
    c.add_subcomponent("led", "led")
    c.add_connection(("pot", "vOut"), ("led", "eIn"))
    c.make_output()
예제 #24
0
파일: car.py 프로젝트: uclalemur/roco
from roco.api.component import Component
from roco.library import *
from roco.library import get_component

if __name__ == "__main__":
    c = Component(name = 'Car')
    c.add_subcomponent('Constant0', 'Constant')
    c.add_subcomponent('Constant1', 'Constant')
    c.add_subcomponent('Constant2', 'Constant')
    c.add_subcomponent('Constant3', 'Constant')
    c.add_subcomponent('DrivenServo0', 'DrivenServo')
    c.add_subcomponent('DrivenServo1', 'DrivenServo')
    c.add_subcomponent('DrivenServo2', 'DrivenServo')
    c.add_subcomponent('DrivenServo3', 'DrivenServo')
    c.add_subcomponent('node_mcu0', 'node_mcu')
    c.add_connection(('node_mcu0', 'do1'), ('DrivenServo0', 'PWMin'))
    c.add_connection(('Constant0', 'num'), ('DrivenServo0', 'inInt'))
    c.add_connection(('node_mcu0', 'do2'), ('DrivenServo1', 'PWMin'))
    c.add_connection(('Constant1', 'num'), ('DrivenServo1', 'inInt'))
    c.add_connection(('node_mcu0', 'do3'), ('DrivenServo2', 'PWMin'))
    c.add_connection(('Constant2', 'num'), ('DrivenServo2', 'inInt'))
    c.add_connection(('node_mcu0', 'do4'), ('DrivenServo3', 'PWMin'))
    c.add_connection(('Constant3', 'num'), ('DrivenServo3', 'inInt'))
    c.get_subcomponent('Constant0').set_parameter('num', '130')
    c.get_subcomponent('Constant1').set_parameter('num', '130')
    c.get_subcomponent('Constant2').set_parameter('num', '130')
    c.get_subcomponent('Constant3').set_parameter('num', '130')
    c.to_yaml("library/car.yaml")
    c.make_output()