k/
errors.rs

1/*
2  Copyright 2017 Takashi Ogura
3
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8      http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15*/
16use nalgebra as na;
17use thiserror::Error;
18
19/// The reason of joint error
20#[derive(Debug, Clone, Error)]
21#[non_exhaustive]
22pub enum Error {
23    /// Failed to set joint angle because the input is out of range or it is fixed joint
24    #[error(
25        "joint: {} is out of limit: {}, limit = {} <=> {}",
26        joint_name,
27        position,
28        max_limit,
29        min_limit
30    )]
31    OutOfLimitError {
32        /// name of the joint
33        joint_name: String,
34        /// target position
35        position: f64,
36        /// max limit
37        max_limit: f64,
38        /// min limit
39        min_limit: f64,
40    },
41    #[error("joint {} is fixed joint but the position is set", joint_name)]
42    SetToFixedError {
43        /// name of the joint
44        joint_name: String,
45    },
46    /// Gave invalid size of vec as input
47    #[error("size mismatch input = {}, required = {}", input, required)]
48    SizeMismatchError {
49        /// size of input
50        input: usize,
51        /// required size
52        required: usize,
53    },
54    /// Error about mimic
55    #[error("mimic error from {} to {}", from, to)]
56    MimicError {
57        /// tried to copy from `from`
58        from: String,
59        /// tried to copy to `to`
60        to: String,
61    },
62    #[error(
63        "ik solve not converged tried {} times, position diff = {}, rotation diff = {}",
64        num_tried,
65        position_diff,
66        rotation_diff
67    )]
68    NotConvergedError {
69        num_tried: usize,
70        position_diff: na::Vector3<f64>,
71        rotation_diff: na::Vector3<f64>,
72    },
73    #[error("inverse matrix error")]
74    InverseMatrixError,
75    #[error(
76        "ik precondition error: input Dof={}, must be greater than {}",
77        dof,
78        necessary_dof
79    )]
80    PreconditionError { dof: usize, necessary_dof: usize },
81    #[error("There is no valid joint named {}", joint_name)]
82    InvalidJointNameError { joint_name: String },
83}