Comments (3)
No, there is currently no such functionality. This library is based on version 1 of the python library wich does not have such utility functions.
As it seems, MotorSet
is primarily used to set a command or get the current state for all assigned motor. But it is not possible to set the speed
or the duty_cycle
for each connected motor. So you either have to use a subclass like MoveTank
which is limited to two motors or keep track of the motors manually to set the individual speeds. It is currently not planed to add higher level functions such as pid controllers, odometry or other such functionality provided by MoveTank
and comparable classes.
But it would be possible to implement a slightly more advanced version of MotorSet
that supports setters for individual speeds of motors. Such an implementation dependents on a subset of RFC-2000 (to check the parameter count for a set_speed
function at compile time) wich is scheduled to for release in stable at 2021-03-25. Here is a proposed usage example:
let motor1 = LargeMotor::get(MotorPort::OutA)?;
let motor2 = LargeMotor::get(MotorPort::OutB)?;
let motor3 = MediumMotor::get(MotorPort::OutC)?;
let motor_set = MotorSet::create<3>([motor1, motor2, motor3]);
motor_set.run_direct()?;
motor_set.set_duty_cycle_sp([50, 70, 30])?;
motor_set.stop()?;
This would achieve the same as:
let motor1 = LargeMotor::get(MotorPort::OutA)?;
let motor2 = LargeMotor::get(MotorPort::OutB)?;
let motor3 = MediumMotor::get(MotorPort::OutC)?;
motor1.run_direct()?;
motor2.run_direct()?;
motor3.run_direct()?;
motor1.set_duty_cycle_sp(50)?;
motor2.set_duty_cycle_sp(70)?;
motor3.set_duty_cycle_sp(30)?;
motor1.stop()?;
motor2.stop()?;
motor3.stop()?;
What would be your intended use case? Would such a MotorSet
struct be sufficient for it?
from ev3dev-lang-rust.
So, again, I'm pretty new to all this, but I'm seeing some driving behavior that I suspect is a timing issue. When I use this Python program, I notice that the robot "kicks" a bit to one side when it starts driving: https://github.com/ev3dev/ev3dev-lang-python-demo/blob/stretch/robots/EXPLOR3R/auto-drive.py
My initial guess here is that it's a timing issue: one wheel starts moving slightly before another, and that acts as a bit of accidental steering. I further guess/hope that if I update that code to use something like a MotorSet
, instead, that the problem will go away. Lot of assumptions here, I know -- I only get a tiny bit of time every so often to play with this stuff.
My current mini project is rewriting that little program in Rust, so I was hoping to use a MotorSet
or somesuch and avoid the question altogether.
from ev3dev-lang-rust.
Yes, such small "kicks" are a typical problem on ev3 robot and it is indeed a timing problem. Unfortunately a MotorSet
cannot solve this problem. It is mostly used for convenience to reduce code size. Here is an example of the set_polarity
function:
for motor in motors:
motor.polarity = polarity
As you can see, this is basically the same implementation as the example code:
for m in motors:
m.duty_cycle_sp = dc
However, it is possible to reduce these "kicks". First you should initialise all properties used, in particular duty_cycle_sp
in your example. Both this and the python library use caching to improve the communication delay with the kernel drivers. At the first call to each property of a motor or sensor, a file handler is opened and stored. All subsequent calls to this property use the already saved file handler. To achieve this, you can add the following code between line 114 and 115 of your linked example.
for m in motors:
m.duty_cycle_sp = 0
And a rust implementation of this example would reduce this "kick" too. Compared to python, rust is a compiled language and generally has better performance (this also applies to I/O operations).
from ev3dev-lang-rust.
Related Issues (20)
- Should all the functions in sensor!() be pub? HOT 2
- BrickPi HOT 3
- Rc<RefCell<File>> cannot be sent between threads safely HOT 1
- Add support for getting "raw" data HOT 1
- way to reduce executable size HOT 2
- `cross` is unnecessary for building? HOT 1
- Ev3Error does not implement Error HOT 1
- TachoMotor trait HOT 1
- Can't get PID values from TachoMotor HOT 2
- error: linking with `c:/msys64/mingw64/bin/arm-none-eabi-gcc.exe` failed: exit code: 1 HOT 2
- Document code hidden behind `screen` feature HOT 2
- Makefile errors on windows
- Cannot control EV3 motors HOT 3
- Example code does not work HOT 6
- screen errors HOT 1
- cross-compilation instructions are confusing HOT 5
- Button Event Listeners. HOT 10
- check if screen uses rgb mode HOT 1
- How can you use the derive macros from a crate that is not inside the library workspace? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ev3dev-lang-rust.