pixix4/ev3dev-lang-rust

Example code does not work

Closed this issue · 6 comments

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

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

  • Is the motor correctly connected to the right port and visible within the ev3 menu?
  • Is the motor speed set to a sufficiently high value?
  • Did the program exit before the motors could execute the commands?
    • Did an error occur and the run command could not be execute?
    • Die the program wait for the command to start/finish?

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

  • The speed is set to 300 (using set_speed_sp)
  • the time is set to 1000 ms (using set_time_sp)
  • motor is being called using run_timed with a duration from seconds 10
    There was no error, the program did execute. The motor is correctly connected I will check if it is visible within the menu.
    From my observation the program did not wait for the command to start or finish
    @pixix4
pixix4 commented

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

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

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.

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