def update_hexapod_plot(alpha, beta, gamma, f, s, m, h, k, a, camera, figure):

    if figure is None:
        HEXAPOD = deepcopy(BASE_HEXAPOD)
        HEXAPOD.update(HEXAPOD_POSE)
        return BASE_PLOTTER.update(HEXAPOD_FIGURE, HEXAPOD)

    virtual_hexapod = VirtualHexapod().new(f or 0, m or 0, s or 0, h or 0, k
                                           or 0, a or 0)

    POSES = deepcopy(HEXAPOD_POSE)

    for k, _ in POSES.items():
        POSES[k] = {
            'id': k,
            'name': NAMES_LEG[k],
            'coxia': alpha,
            'femur': beta,
            'tibia': gamma,
        }

    virtual_hexapod.update(POSES)

    if camera is not None:
        figure = BASE_PLOTTER.change_camera_view(figure, json.loads(camera))

    return BASE_PLOTTER.update(figure, virtual_hexapod)
Ejemplo n.º 2
0
def update_graph(poses_json, measurements_json, relayout_data, figure):

  if figure is None:
    HEXAPOD = deepcopy(BASE_HEXAPOD)
    HEXAPOD.update(HEXAPOD_POSE)
    return BASE_PLOTTER.update(HEXAPOD_FIGURE, HEXAPOD)

  if measurements_json is None:
    raise PreventUpdate

  # Make base hexapod model given body measurements
  measurements = json.loads(measurements_json)
  virtual_hexapod = VirtualHexapod(measurements)
  
  # Configure the pose of the hexapod given joint angles
  if poses_json is not None:
    try:
      poses = json.loads(poses_json)
    except:
      print("can't parse:", poses)
    
    virtual_hexapod.update(poses)

  # Update the plot to reflect pose of hexapod
  figure = BASE_PLOTTER.update(figure, virtual_hexapod)

  # Use current camera view to display plot
  if relayout_data and 'scene.camera' in relayout_data:
    camera = relayout_data['scene.camera']
    figure = BASE_PLOTTER.change_camera_view(figure, camera)

  return figure
Ejemplo n.º 3
0
def update_patterns_page(dimensions_json, poses_json, relayout_data, figure):

    dimensions = helpers.load_params(dimensions_json, "dims")
    poses = helpers.load_params(poses_json, "pose")
    hexapod = VirtualHexapod(dimensions)

    try:
        hexapod.update(poses)
    except Exception as alert:
        return figure, helpers.make_alert_message(alert)

    BASE_PLOTTER.update(figure, hexapod)
    helpers.change_camera_view(figure, relayout_data)
    return figure, ""
def update_kinematics_page(dimensions_json, poses_json, relayout_data, figure):
    if figure is None:
        return BASE_FIGURE, ""

    dimensions = helpers.load_dimensions(dimensions_json)
    poses = json.loads(poses_json)
    hexapod = VirtualHexapod(dimensions)

    try:
        hexapod.update(poses)
    except Exception as alert:
        return figure, helpers.make_alert_message(alert)

    BASE_PLOTTER.update(figure, hexapod)
    helpers.change_camera_view(figure, relayout_data)
    return figure, ""
Ejemplo n.º 5
0
def update_inverse_page(dimensions_json, ik_parameters_json, relayout_data, figure):

    dimensions = helpers.load_params(dimensions_json, "dims")
    ik_parameters = helpers.load_params(ik_parameters_json, "ik")
    hexapod = VirtualHexapod(dimensions)

    try:
        poses, hexapod = inverse_kinematics_update(hexapod, ik_parameters)
    except Exception as alert:
        return figure, helpers.make_alert_message(alert)

    if RECOMPUTE_HEXAPOD:
        try:
            hexapod = recompute_hexapod(dimensions, ik_parameters, poses)
        except Exception as alert:
            return figure, helpers.make_alert_message(alert)

    BASE_PLOTTER.update(figure, hexapod)
    helpers.change_camera_view(figure, relayout_data)
    return figure, helpers.make_poses_message(poses)
def change_camera_view(figure, relayout_data):
    if relayout_data and "scene.camera" in relayout_data:
        camera = relayout_data["scene.camera"]
        BASE_PLOTTER.change_camera_view(figure, camera)

    return figure