tendon/
tendon.rs

1//! Example of using sensor interaction: touch sensor.
2use std::time::Duration;
3
4use mujoco_rs::viewer::MjViewer;
5use mujoco_rs::prelude::*;
6
7
8const EXAMPLE_MODEL: &str = "
9<mujoco>
10    <worldbody>
11        <light ambient=\"0.2 0.2 0.2\"/>
12        
13        <body name=\"ball1\" pos=\"-.5 0 0\">
14            <geom size=\".1\" rgba=\"0 1 0 1\" mass=\"1\"/>
15            <joint type=\"free\"/>
16            <site name=\"ball1\" size=\".1 .1 .1\" pos=\"0 0 0\" rgba=\"0 1 0 0.2\" type=\"box\"/>
17        </body>
18
19        <body name=\"ball2\"  pos=\".5 0 0\">
20            <geom size=\".1\" rgba=\"0 1 1 1\" mass=\"1\"/>
21            <joint type=\"free\"/>
22            <site name=\"ball2\" size=\".1 .1 .1\" pos=\"0 0 0\" rgba=\"0 1 1 0.2\" type=\"box\"/>
23        </body>
24
25        <geom name=\"floor\" type=\"plane\" size=\"10 10 1\"/>
26    </worldbody>
27
28    <tendon>
29        <spatial limited=\"true\" range=\"0 1\" rgba=\"0 .1 1 1\" width=\".005\">
30        <site site=\"ball1\"/>
31        <site site=\"ball2\"/>
32        </spatial>
33    </tendon>
34</mujoco>
35";
36
37fn main() {
38    /* Load the model and create data */
39    let model = MjModel::from_xml_string(EXAMPLE_MODEL).expect("could not load the model");
40    let mut data = model.make_data();  // or MjData::new(&model);
41
42    /* Launch a passive Rust-native viewer */
43    let mut viewer = MjViewer::launch_passive(&model, 0)
44        .expect("could not launch the viewer");
45
46    while viewer.running() {
47        /* Step the simulation and sync the viewer */
48        viewer.sync(&mut data);
49        data.step();
50
51        std::thread::sleep(Duration::from_secs_f64(0.002));
52    }
53}