pixix4 / ev3dev-lang-rust

Rust language bindings for http://ev3dev.org
MIT License
73 stars 14 forks source link

Example code does not work #26

Closed spacey-sooty closed 1 year ago

spacey-sooty commented 1 year ago

I have compiled the example code and downloaded it on my EV3 and it doesn't move the motor. I have tried to use other methods of moving the motors but it is not working.

pixix4 commented 1 year ago

Can you give some more information about what you tried? My first ideas would be:

spacey-sooty commented 1 year ago

In my attempt to fix the example code I used these values

pixix4 commented 1 year ago

Can you post your code? Then I can try to check for bugs in the library on the weekend.

spacey-sooty commented 1 year ago

main.rs

extern crate ev3dev_lang_rust;

use ev3dev_lang_rust::Ev3Result;
use ev3dev_lang_rust::motors::{LargeMotor, MotorPort};

fn main()  -> Ev3Result<()> {
    let large_motor = LargeMotor::get(MotorPort::OutA)?;

    large_motor.set_speed_sp(300)?;

    large_motor.set_time_sp(1000)?;

    large_motor.run_timed(Some(std::time::Duration::from_secs(10)))?;

    Ok(())
}

I also tried using large_motor.run_forever()?;

pixix4 commented 1 year ago

Sorry for the late reply, but I couldn't reproduce your problem. After I started this sample program, the A motor spun for 10 seconds. As you mentioned, the program didn't wait for the motor to finish. At the moment I can only guess that there is a service that automatically stops all motors after the program finishes (to prevent unintentional movements). To test this, you could try adding a wait time at the end. Or you could explicitly wait until the motor finishes spinning with “large_motor.wait_until_not_moving(None);”.

Regardless, the run_timed and run_forever commands seem to work as expected. As a minor node: The duration parameter of run_timed overrides the set_time_sp call. So in your example the motor ignores the time setpoint of 1000 ms and runs for 10 seconds.

spacey-sooty commented 1 year ago

Right thank you for the help I will see if I can figure this out over the week