|
| 1 | +use serde::Deserialize; |
| 2 | +use crate::common::*; |
| 3 | + |
| 4 | +#[derive(Debug, Deserialize, Clone)] |
| 5 | +#[serde(rename_all = "snake_case")] |
| 6 | +pub enum Geometry { |
| 7 | + Empty, |
| 8 | + Box { |
| 9 | + #[serde(with = "ss_vec3")] |
| 10 | + size: [f64; 3], |
| 11 | + }, |
| 12 | + Capsule { |
| 13 | + radius: f64, |
| 14 | + length: f64, |
| 15 | + }, |
| 16 | + Cylinder { |
| 17 | + radius: f64, |
| 18 | + length: f64, |
| 19 | + }, |
| 20 | + // Ellipsoid, |
| 21 | + // Heightmap, |
| 22 | + // Image, |
| 23 | + Mesh { |
| 24 | + filename: String, |
| 25 | + #[serde(with = "crate::common::ss_option_vec3", default)] |
| 26 | + scale: Option<[f64; 3]>, |
| 27 | + }, |
| 28 | + // Plane, |
| 29 | + // Polyline, |
| 30 | + Sphere { |
| 31 | + radius: f64, |
| 32 | + }, |
| 33 | +} |
| 34 | + |
| 35 | +impl Default for Geometry { |
| 36 | + fn default() -> Geometry { |
| 37 | + Geometry::Box { |
| 38 | + size: [0.0f64, 0.0, 0.0], |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +#[derive(Debug, Deserialize, Default, Clone)] |
| 44 | +pub struct Material { |
| 45 | + pub name: String, |
| 46 | + pub color: Option<ColorRGBA>, |
| 47 | + pub texture: Option<Texture>, |
| 48 | +} |
| 49 | + |
| 50 | +#[derive(Debug, Deserialize, Default, Clone)] |
| 51 | +pub struct Visual { |
| 52 | + pub name: Option<String>, |
| 53 | + #[serde(default)] |
| 54 | + pub origin: Pose, |
| 55 | + pub geometry: Geometry, |
| 56 | + pub material: Option<Material>, |
| 57 | +} |
| 58 | + |
| 59 | +/// Urdf Link element |
| 60 | +/// See <http://wiki.ros.org/urdf/XML/link> for more detail. |
| 61 | +#[derive(Debug, Deserialize, Clone)] |
| 62 | +pub struct Link { |
| 63 | + pub name: String, |
| 64 | + #[serde(default)] |
| 65 | + pub pose: Pose, |
| 66 | + #[serde(default)] |
| 67 | + pub visual: Vec<Visual>, |
| 68 | +} |
| 69 | + |
| 70 | +#[derive(Debug, Deserialize, Clone)] |
| 71 | +pub struct Axis { |
| 72 | + #[serde(with = "crate::common::ss_vec3")] |
| 73 | + pub xyz: [f64; 3], |
| 74 | +} |
| 75 | + |
| 76 | +impl Default for Axis { |
| 77 | + fn default() -> Axis { |
| 78 | + Axis { |
| 79 | + xyz: [0.0f64, 0.0, 1.0], |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +#[derive(Debug, Deserialize, Clone)] |
| 85 | +pub struct Pose { |
| 86 | + #[serde(with = "crate::common::ss_vec3")] |
| 87 | + #[serde(default = "default_zero3")] |
| 88 | + pub xyz: [f64; 3], |
| 89 | + #[serde(with = "crate::common::ss_vec3")] |
| 90 | + #[serde(default = "default_zero3")] |
| 91 | + pub rpy: [f64; 3], |
| 92 | +} |
| 93 | + |
| 94 | +fn default_zero3() -> [f64; 3] { |
| 95 | + [0.0f64, 0.0, 0.0] |
| 96 | +} |
| 97 | + |
| 98 | +impl Default for Pose { |
| 99 | + fn default() -> Pose { |
| 100 | + Pose { |
| 101 | + xyz: default_zero3(), |
| 102 | + rpy: default_zero3(), |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +#[derive(Debug, Deserialize, Clone)] |
| 108 | +pub struct LinkName { |
| 109 | + pub link: String, |
| 110 | +} |
| 111 | + |
| 112 | +#[derive(Debug, Deserialize, Clone, PartialEq, Eq)] |
| 113 | +#[serde(rename_all = "snake_case")] |
| 114 | +pub enum JointType { |
| 115 | + Revolute, |
| 116 | + Continuous, |
| 117 | + Prismatic, |
| 118 | + Fixed, |
| 119 | + Floating, |
| 120 | + Planar, |
| 121 | + Spherical, |
| 122 | +} |
| 123 | + |
| 124 | +#[derive(Debug, Deserialize, Default, Clone)] |
| 125 | +pub struct JointLimit { |
| 126 | + #[serde(default)] |
| 127 | + pub lower: f64, |
| 128 | + #[serde(default)] |
| 129 | + pub upper: f64, |
| 130 | + pub effort: f64, |
| 131 | + pub velocity: f64, |
| 132 | +} |
| 133 | + |
| 134 | +/// Urdf Joint element |
| 135 | +/// See <http://wiki.ros.org/urdf/XML/joint> for more detail. |
| 136 | +#[derive(Debug, Deserialize, Clone)] |
| 137 | +pub struct Joint { |
| 138 | + pub name: String, |
| 139 | + #[serde(rename = "type")] |
| 140 | + pub joint_type: JointType, |
| 141 | + #[serde(default)] |
| 142 | + pub origin: Pose, |
| 143 | + pub parent: LinkName, |
| 144 | + pub child: LinkName, |
| 145 | + #[serde(default)] |
| 146 | + pub axis: Axis, |
| 147 | + #[serde(default)] |
| 148 | + pub limit: JointLimit, |
| 149 | +} |
| 150 | + |
| 151 | +/// Top level struct to access urdf. |
| 152 | +#[derive(Debug, Deserialize, Clone)] |
| 153 | +pub struct Robot { |
| 154 | + #[serde(default)] |
| 155 | + pub name: String, |
| 156 | + |
| 157 | + #[serde(rename = "link", default)] |
| 158 | + pub links: Vec<Link>, |
| 159 | + |
| 160 | + #[serde(rename = "joint", default)] |
| 161 | + pub joints: Vec<Joint>, |
| 162 | + |
| 163 | + #[serde(rename = "material", default)] |
| 164 | + pub materials: Vec<Material>, |
| 165 | +} |
0 commit comments