Exemplo n.º 1
0
def manual_control(request, vehicle_id=0):
    # 本当はvehicle_idでDB検索して存在しなければ404出したほうがいいんだけど、
    # 手動操作っていう性質上パフォーマンスを重視したいのでやってない。
    speed = int(request.POST.get('speed', 0))
    stair_angle = int(request.POST.get('stair_angle', 0))
    fork_up = int(request.POST.get('fork_up', 0))
    tilt_up = int(request.POST.get('tilt_up', 0))

    fork_up_value = 0
    if fork_up == 1:
        fork_up_value = 2500  # 現場で調整した値
    elif fork_up == -1:
        fork_up_value = 75  # 現場で調整した値

    tilt_up_value = 0
    if tilt_up == 1:
        tilt_up_value = 1
    elif tilt_up == -1:
        tilt_up_value = -1

    # データ作成して送信
    send_data = utility.to_hex(0, 2) + \
                utility.to_hex(utility.to_can_signed(speed), 4) + \
                utility.to_hex(utility.to_can_signed(stair_angle), 4) + \
                utility.to_hex(utility.to_can_signed(fork_up_value), 4) + \
                utility.to_hex(utility.to_can_signed(tilt_up_value, for_1_byte=True), 2)
    mqtt.send(vehicle_id,
              can_const.CAN_ID_SND_MANUAL_CTRL,
              send_data,
              qos=mqtt.MQTT_QOS_NORMAL)

    return JsonResponse({"result": True})
Exemplo n.º 2
0
def auto_control_flag(request, vehicle_id=0):
    set_auto_flag = int(request.POST.get('set_auto_flag', 0))

    # データ作成して送信
    send_data = utility.to_hex(0, 4) + utility.to_hex(
        set_auto_flag, 2) + utility.to_hex(0, 10)
    mqtt.send(vehicle_id, can_const.CAN_ID_SND_ACTION, send_data)

    return JsonResponse({"result": True})
Exemplo n.º 3
0
    def __send_route_data(cls, vehicle_id, populated_data):
        # 位置
        can_data = (
            utility.to_hex(populated_data["index"]) +
            utility.to_hex(utility.to_can_signed(populated_data["x"])) +
            utility.to_hex(utility.to_can_signed(populated_data["y"])) +
            utility.to_hex(utility.to_can_signed(populated_data["speed"]))
        )
        time.sleep(cls.CAN_SEND_WAIT_TIME_SEC)
        mqtt.send(vehicle_id, can_const.CAN_ID_SND_MAP_INFO_1, can_data)

        # 荷上下げ関係すればflag_stopをON
        if populated_data["task"] == can_const.ROUTE_TASK_LIFTUP \
                or populated_data["task"] == can_const.ROUTE_TASK_LIFTUP_WITH_TURN \
                or populated_data["task"] == can_const.ROUTE_TASK_LIFTDOWN \
                or populated_data["task"] == can_const.ROUTE_TASK_LIFTDOWN_WITH_TURN:
            populated_data["flag_stop"] = 1

        # タスク
        can_data = (
            utility.to_hex(populated_data["index"]) +
            utility.to_hex(populated_data["task"], 2) +
            utility.to_hex(populated_data["flag_stop"], 2) +
            utility.to_hex(utility.to_can_signed(populated_data["angle"])) +
            utility.to_hex(utility.to_can_signed(populated_data["height_lift"]))
        )
        time.sleep(cls.CAN_SEND_WAIT_TIME_SEC)
        mqtt.send(vehicle_id, can_const.CAN_ID_SND_MAP_INFO_2, can_data)
Exemplo n.º 4
0
def operation_flag(request, vehicle_id=0):
    emergency_flag = int(request.POST.get('emergency_flag', 0))
    demo_obstacle_flag_1 = int(request.POST.get('demo_obstacle_flag_1', 0))
    demo_obstacle_flag_2 = int(request.POST.get('demo_obstacle_flag_2', 0))

    # データ作成して送信
    send_data = \
        utility.to_hex(emergency_flag, 2) + \
        utility.to_hex(demo_obstacle_flag_1, 2) + \
        utility.to_hex(demo_obstacle_flag_2, 2) + \
        utility.to_hex(0, 10)

    mqtt.send(vehicle_id, can_const.CAN_ID_SND_EMERGENCY, send_data)

    return JsonResponse({"result": True})
Exemplo n.º 5
0
    def execute_route_operation(cls, vehicle_operation_plan_id=-1):

        # ルート情報を取得する(取得不可なら500で落ちる)
        vehicle_operation_plan = VehicleOperationPlan.objects.get(pk=vehicle_operation_plan_id)
        route_operation_json = json.loads(vehicle_operation_plan.route_operation_json)
        if len(route_operation_json) == 0:
            raise ValueError

        # なにもしないタスク(255)は送らない
        edit_route_operation = []
        for row in route_operation_json:
            if row["task"] != can_const.ROUTE_TASK_NOTHING:
                edit_route_operation.append(row)

        # AfterTaskを2行で送信する場合は件数確認
        route_count = len(edit_route_operation)
        for row in edit_route_operation:
            if row["afterTask"] != can_const.ROUTE_TASK_NOTHING:
                route_count += 1

        # TODO: バグ?件数が1件多くなる
        route_count = route_count - 1

        # 件数を取得してPreMap送信
        mqtt.send(vehicle_operation_plan.vehicle_id, can_const.CAN_ID_SND_MAP_PRE_INFO,
                  utility.to_hex(vehicle_operation_plan_id) + utility.to_hex(route_count) + "00000000")

        time.sleep(cls.CAN_SEND_WAIT_TIME_SEC)

        for i in range(2):  # どうにもECUがCANを取りこぼすので2回連続で送る
            index = 1
            for row in edit_route_operation:

                # 初期値設定&Populate
                data = {
                    "index": index,
                    "x": int(float(row.get("x", 0)) * 1000),
                    "y": int(float(row.get("y", 0)) * 1000),
                    "speed": int(row.get("speed", 1000)),
                    "task": int(row.get("task", 255)),
                    "after_task": int(row.get("afterTask", 255)),
                    "flag_stop": 0,
                    "angle": int(row.get("angle", 0)),
                    "height_lift": int(row.get("liftHeight", 0))
                }

                # 最後の行なら必ずflag_stopをONにする
                if index == len(edit_route_operation):
                    data["flag_stop"] = 1

                # 送信
                cls.__send_route_data(vehicle_operation_plan.vehicle_id, data)

                # AfterTaskが定義されていれば、AfterTaskをTaskに置き換えて再送信
                if data["after_task"] != 255:
                    data["task"] = data["after_task"]
                    cls.__send_route_data(vehicle_operation_plan.vehicle_id, data)

                index += 1

        # 実行開始
        time.sleep(cls.CAN_SEND_WAIT_TIME_SEC)
        mqtt.send(vehicle_operation_plan.vehicle_id, can_const.CAN_ID_SND_ACTION,
                  utility.to_hex(vehicle_operation_plan_id) + utility.to_hex(1, 2) + utility.to_hex(1, 2) + "00000000")