basic/
basic.rs

1use servo_libs_simulator::{ServoSystem, ServoChannel, ServoSpec};
2
3fn main() {
4    let mut system = ServoSystem::new();
5
6    // MG996R 6 channels robot arms example
7    system.add_channel(ServoChannel::new(0, "base", ServoSpec::mg996r()));
8    system.add_channel(ServoChannel::new(1, "shoulder", ServoSpec::mg996r()));
9    system.add_channel(ServoChannel::new(2, "elbow", ServoSpec::mg996r()));
10    system.add_channel(ServoChannel::new(3, "wrist_pitch", ServoSpec::mg996r()));
11    system.add_channel(ServoChannel::new(4, "wrist_roll", ServoSpec::mg996r()));
12    system.add_channel(ServoChannel::new(5, "gripper", ServoSpec::mg996r()));
13
14    // angle control
15    if let Some(servo) = system.get_channel_mut(0) {
16        servo.set_angle(90.0);
17        println!("Base angle = {}, pulse = {}", servo.angle, servo.get_pulse());
18    }
19
20    // pulse control
21    if let Some(servo) = system.get_channel_mut(1) {
22        servo.set_pulse(350);
23        println!("Shoulder pulse=350 -> angle = {}", servo.angle);
24    }
25}