Esempio n. 1
0
def test_scan():
    earley = Earley('a')
    earley.rules_list = [Rule('U', 'S'), Rule('S', 'a')]
    earley.situations_dict[0].add(Situation('S', 'a', 0, 0))
    earley.scan(0, 'a')

    is_added = False
    to_add = Situation('S', 'a', 0, 1)
    for sit in earley.situations_dict[1]:
        if sit == to_add:
            is_added = True
            break

    assert is_added
Esempio n. 2
0
def generate_trace(db_path):
    db = DataBase(db_path)

    t = Trace()
    s = Situation()

    # Robot/Operator moving status
    moving_topics = {
        "/safety/robot/moving": s.robot.is_moving,
        "/safety/operator/moving": s.operator.is_moving,
    }
    for c in moving_topics.values():
        t[c] = (0.0, False)
    for m in from_table(db, "movablestatus"):
        if m.topic in moving_topics:
            t[moving_topics[m.topic]] = (m.timestamp, m.is_moving == 1)

    # Collision occurrences
    t[s.collision.occurs] = (0.0, False)
    t[s.collision.force] = (0.0, 0.0)
    for m in from_table(db, "collisionevent"):
        if m.entity_id == "Operator-Tim":
            t[s.collision.occurs] = (m.timestamp, True)
            t[s.collision.force] = (m.timestamp, m.collision_force)
            t[s.collision.occurs] = (m.timestamp + 0.01, False)
            t[s.collision.force] = (m.timestamp + 0.01, 0.0)

    # LIDAR Measurements
    t[s.lidar.distance] = (0.0, float("inf"))
    for m in from_table(db, "float32"):
        if m.topic == "/lidar/digital/range":
            t[s.lidar.distance] = (m.timestamp, m.data)

    return t
Esempio n. 3
0
    def complete(self, list_number):
        situations_to_insert = []
        for situation in self.situations_dict[list_number]:
            list_number_2 = situation.index
            if situation.point == len(situation.output):
                for situation_2 in self.situations_dict[list_number_2]:
                    sit = Situation(situation_2.input, situation_2.output, situation_2.index, situation_2.point + 1)
                    situations_to_insert.append(sit)

        for situation in situations_to_insert:
            self.add_situation(situation, list_number)
Esempio n. 4
0
    def predict(self, list_number):
        situations_to_insert = []
        for situation in self.situations_dict[list_number]:
            if situation.point < len(situation.output):
                nonterminal = situation.output[situation.point]
                for rule in self.rules_list:
                    if rule.input == nonterminal:
                        sit = Situation(nonterminal, rule.output, list_number, 0)
                        situations_to_insert.append(sit)

        for situation in situations_to_insert:
            self.add_situation(situation, list_number)
Esempio n. 5
0
    def __init__(self):
        super().__init__(daemon=True)
        self.name = 'EngineThread'
        self.state = self.ENGINE_BOOT

        self.sit = Situation()
        self.stack = [self.sit]

        self.index = 0
        self.running = False
        self.usemillisec = True
        self.millisec = 1
Esempio n. 6
0
def test_predict():
    earley = Earley('a')
    earley.rules_list = [Rule('U', 'S'), Rule('S', 'a')]
    earley.predict(0)

    is_added = False
    to_add = Situation('S', 'a', 0, 0)
    for sit in earley.situations_dict[0]:
        if sit == to_add:
            is_added = True
            break

    assert is_added
Esempio n. 7
0
def find_situations(concerns):
    # management of the first concern
    intro_sit_file = open('data/fixed_texts/intro_situations.txt', "r")
    sm.my_print_file(intro_sit_file, FLAG)
    intro_sit_file.close()
    # replacement of * in the questions with the concern LEO is facing at the moment
    uncompleted_question = sm.choose_sentence("situations")
    question = sm.replace_a_star(uncompleted_question,
                                 concerns[0].get_concern())
    sm.my_print_string(question, FLAG)
    answer = input()
    new_answer, keywords_list = analyze_answer(answer)
    for keyword in keywords_list:
        situation = sm.complete_keywords(new_answer, keyword[0])
        concerns[0].add_situation(Situation(situation))
    return concerns, answer
Esempio n. 8
0
def makeCorpus(world, wordFile, objectFile):
    # Input: World object, filenames of word and object files
    # Output: Corpus as list of Situations
    corpus = []
    wf = open(wordFile, 'r')
    of = open(objectFile, 'r')

    wl = wf.readline()
    ol = of.readline()
    while (len(wl) != 0 and len(ol) != 0):
        wl = processLine(wl)
        ol = processLine(ol)

        words = [world.words_key.index(x) for x in wl.split(' ') if x != '']
        objects = [
            world.objects_key.index(x) for x in ol.split(' ') if x != ''
        ]
        corpus.append(Situation(words, objects))

        wl = wf.readline()
        ol = of.readline()
    return corpus
Esempio n. 9
0
 def __init__(self, word):
     situation = Situation('U', 'S', 0, 0)
     self.situations_dict = {i: set() for i in range(len(word) + 1)}
     self.situations_dict[0].add(situation)
     self.word = word
Esempio n. 10
0
 def scan(self, list_number, symbol):
     for situation in self.situations_dict[list_number]:
         if situation.output[situation.point] == symbol:
             sit = Situation(situation.input, situation.output, situation.index, situation.point + 1)
             self.add_situation(sit, list_number + 1)
Esempio n. 11
0
from situation import Situation

_S = Situation()

_COLLISION_FORCE_THRESHOLD = 100

# Any contact between the robot and operator
contact_occurs = _S.collision.occurs.eventually()

# Any hazardous contact between the robot and operator
collision_occurs = (_S.collision.occurs & _S.collision.force >
                    _COLLISION_FORCE_THRESHOLD).eventually()

# Any contact due to the operator moving into a stopped robot
operator_collides = (_S.collision.occurs & ~_S.robot.is_moving).eventually()

# The robot stops within 250ms when an obstacle gets too close
_SAFETY_STOP_THRESHOLD = 0.75
robot_safety_stops = ((_S.lidar.distance < _SAFETY_STOP_THRESHOLD).implies(
    (~_S.robot.is_moving)
    | (~_S.robot.is_moving).eventually(hi=0.250))).always()

monitored_conditions = {
    "Contact between operator and robot": contact_occurs,
    "Collision between operator and robot": collision_occurs,
    "Operator collides with robot": operator_collides,
    "Robot performs safety stop": robot_safety_stops,
}
Esempio n. 12
0
 def __init__(self) -> None:
     self.callback = None
     self.sit = Situation()
Esempio n. 13
0
def main():
    # コマンドライン引数を読む
    args = read_args()

    # confファイルの読み込み
    conf = configparser.ConfigParser()
    conf.read('./setting.ini', 'UTF-8')

    # log設定
    logging.basicConfig(level=logging.DEBUG,
                        format="%(relativeCreated)08d[ms] - %(name)s - %(levelname)s - %(processName)-10s - %(threadName)s -\n*** %(message)s",
                        filename="log/app.log",
    )

    # 歩きスマホ人数
    arukisumaho_num = 0
    # 人数
    person_num = 0

    if args.img:
        img = abspath(args.img)
    else:
        # 画像ファイル名を設定
        basename = datetime.now().strftime("%Y%m%d-%H%M%S")
        img = "./media/"+basename+".jpg"

        # 画像を撮影
        wc = Webcam(conf.get("webcam", 'ip') ,
                    conf.get("webcam", 'port') ,
                    conf.get("webcam", 'user') ,
                    conf.get("webcam", 'password')
        )
        wc.setup_basic_auth()
        wc.take_picture(img)

    # 写真が存在しない場合終了する
    if not exists(img):
        print('画像がないよ')
        return

    # インスタンス作成
    situation = Situation()
    pm = ProjectionMapping(
        conf.get("vpt", 'ip') ,
        conf.getint("vpt", 'port')
        )

    # 最初に車の動画を流す
    pm.waiting()

    while True:
        if not args.img:
            wc.take_picture(img)
        situation.recognize(img)
        person_num = situation.get_person_num()
        arukisumaho_num = situation.get_arukisumaho_num()
        print('検出された人数: %d' % person_num)
        print('歩きスマホ人数: %d' % arukisumaho_num)

        try :
            # 歩きスマホいる場合
            if arukisumaho_num >= 1:
                pm.arukisumaho()
                sleep(10) # TODO : 動画時間入れる
                pm.waiting()
            else:
                # 歩行者が大勢いる場合
                if person_num > 1:
                    pm.wide_cross()
                    sleep(10) # TODO : 動画時間入れる
                    pm.waiting()
                # 歩行者ひとりいる場合
                elif person_num == 1:
                    pm.normal_cross()
                    sleep(10) # TODO : 動画時間入れる
                    pm.waiting()
                # 歩行者がいない場合
                else:
                    sleep(3)
                    pass

        except KeyboardInterrupt:
            pm.waiting()