pub fn from_urdf(
xml_content: String,
joint_names: &Option<[&str; 6]>,
) -> Result<URDFParameters, ParameterError>
Expand description
Parses URDF XML content to construct OPW kinematics parameters for a robot.
This function provides detailed error handling through the ParameterError
type,
and returns intermediate type from where both Parameters and Constraints can be taken
and inspected or modified if so required.
§Parameters
xml_content
: AString
containing the XML data of the URDF file.joint_names
: An optional array containing joint names. This may be required if names do not follow typical naming convention, or there are multiple robots defined in URDF. For 5 DOF robots, use the name of the tool center point instead of “joint6”
§Returns
- Returns a
Result<URDFParameters, ParameterError>
. On success, it contains the OPW kinematics configuration for the robot. On failure, it returns a detailed error. Ust to_robot method to convert OpwParameters directly to the robot instance.
§Example showing full control over how the inverse kinematics solver is constructed:
use std::f64::consts::PI;
use rs_opw_kinematics::constraints::BY_PREV;
use rs_opw_kinematics::kinematic_traits::{Joints, JOINTS_AT_ZERO, Kinematics};
use rs_opw_kinematics::kinematics_impl::OPWKinematics;
use rs_opw_kinematics::urdf::from_urdf;
// Exactly this string would fail. Working URDF fragment would be too long for this example.
let xml_data = String::from("<robot><joint ...></joint></robot>");
// Let's assume the joint names have prefix and the joints are zero base numbered.
let joints = ["lf_joint_0", "lf_joint_1", "lf_joint_2", "lf_joint_3", "lf_joint_4", "lf_joint_5"];
let offsets = [ 0., PI, 0., 0.,0.,0.];
let opw_params = from_urdf(xml_data, &Some(joints));
match opw_params {
Ok(opw_params) => {
println!("Building the IK solver {:?}", opw_params);
let parameters = opw_params.parameters(&JOINTS_AT_ZERO); // Zero joint offsets
let constraints =opw_params.constraints(BY_PREV);
let robot = OPWKinematics::new_with_constraints(parameters, constraints);
// let joints = robot.inverse( ... )
}
Err(e) => println!("Error processing URDF: {}", e),
}