// Copyright 2018 The Cartographer Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

import "cartographer/pose_graph/proto/node.proto";
import "cartographer/transform/proto/transform.proto";

package cartographer.pose_graph.proto;

message RelativePose2D {
  NodeId first = 1;
  NodeId second = 2;

  message Parameters {
    transform.proto.Rigid2d first_t_second = 1;
    double translation_weight = 2;
    double rotation_weight = 3;
  }
  Parameters parameters = 3;
}

message RelativePose3D {
  NodeId first = 1;
  NodeId second = 2;

  message Parameters {
    transform.proto.Rigid3d first_t_second = 1;
    double translation_weight = 2;
    double rotation_weight = 3;
  }
  Parameters parameters = 3;
}

message Acceleration3D {
  NodeId first = 1;
  NodeId second = 2;
  NodeId third = 3;
  NodeId imu_calibration = 4;

  message Parameters {
    transform.proto.Vector3d delta_velocity_imu_frame = 1;
    double first_to_second_delta_time_seconds = 2;
    double second_to_third_delta_time_seconds = 3;
    double scaling_factor = 4;
  }
  Parameters parameters = 5;
}

message Rotation3D {
  NodeId first = 1;
  NodeId second = 2;
  NodeId imu_calibration = 3;

  message Parameters {
    transform.proto.Quaterniond delta_rotation_imu_frame = 1;
    double scaling_factor = 2;
  }
  Parameters parameters = 4;
}

message InterpolatedRelativePose2D {
  NodeId first_start = 1;
  NodeId first_end = 2;
  NodeId second = 3;

  message Parameters {
    transform.proto.Rigid3d first_t_second = 1;
    double translation_weight = 2;
    double rotation_weight = 3;
    transform.proto.Quaterniond gravity_alignment_first_start = 4;
    transform.proto.Quaterniond gravity_alignment_first_end = 5;
     // Interpolates between first_start and first_end.
    double interpolation_factor = 6;
  }
  Parameters parameters = 4;
}

message InterpolatedRelativePose3D {
  NodeId first_start = 1;
  NodeId first_end = 2;
  NodeId second = 3;

  message Parameters {
    transform.proto.Rigid3d first_t_second = 1;
    double translation_weight = 2;
    double rotation_weight = 3;
    // Interpolates between first_start and first_end.
    double interpolation_factor = 4;
  }
  Parameters parameters = 4;
}

message CostFunction {
  oneof type {
    RelativePose2D relative_pose_2d = 1;
    RelativePose3D relative_pose_3d = 2;
    Acceleration3D acceleration_3d = 3;
    Rotation3D rotation_3d = 4;
    InterpolatedRelativePose2D interpolated_relative_pose_2d = 5;
    InterpolatedRelativePose3D interpolated_relative_pose_3d = 6;
  }
}
