Comments (16)
The angle
and rate
getters set the mode to the one that is specific to that property, so yes, you can't use them if you want to be in GYRO-G&A
mode. For that you'd need to set the mode yourself and then read from the two value attributes.
@dlech Is there any detriment to performance or angle data if you are in the G&A
mode instead of the property-specific one? i.e. would it be bad if both of those getters used the G&A
mode and read their respective values?
from ev3dev-lang-cpp.
Dunno, you would have to do an experiment to find out. Whether it is bad or not depends on if you care that the getters also set the corresponding mode.
from ev3dev-lang-cpp.
Coincidentally, I think that setting the mode on each call to angle
or rate
is triggering a bug.
I'm currently not attempting to use the G&A mode, just RATE mode. I have a robot that is trying to read the rate of two gyros in a tight control loop (100 Hz).
When I use the rate
method, between ~100 and ~1000 iterations of the control loop, I get a std::system_error: Connection timed out
exception. If I use the value(0)
method, I seem to be able to run my robot indefinitely (no exceptions). The only difference is the call to set_mode
...
from ev3dev-lang-cpp.
Sorry for being silent on this, was away on vacation.
When I use the rate method, between ~100 and ~1000 iterations of the control loop, I get a std::system_error: Connection timed out exception.
A possible workaround for this would be to cache the current mode in a private class field and only set the mode when necessary. This could fail if mode is changed outside of the current process or from a different class instance referencing the same sensor. I think both of these should be extremely rare, and the latter is bad practice anyway.
We could also read the current value of mode just before reading the value and update the mode if necessary. That could be even faster than setting the mode every time and may be less error-prone.
@dsharlet, @dlech, what do you think?
from ev3dev-lang-cpp.
It is rare, but in some cases, you actually do have to set the mode to get an updated value, for example the US-SI-CM
of the LEGO EV3 Ultrasonic sensor. So, I think always setting the mode before reading the value is the correct thing to do for a general use case.
However, having an alternate way to read the value without setting the mode for advanced users that want to read the value as fast as possible makes sense too.
For this particular issue though, I think the question is there are rate()
and angle()
functions, but why is there not a rate_and_angle()
function that corresponds to the GYRO-G&A
mode of the LEGO EV3 Gyro sensor?
from ev3dev-lang-cpp.
but why is there not a rate_and_angle() function that corresponds to the GYRO-G&A mode of the LEGO EV3 Gyro sensor?
Good question and good idea
from ev3dev-lang-cpp.
Good question and good idea
After some thought I don't see a clear way to implement this. The problem is, we only have types for int
, string
, and set of strings
so far in the specification. And in order to define the GYRO-G&A
mode we need a tuple (or its equivalent in a specific language). I see three options for doing this:
-
Only change the definition of the gyroSensor, so that its sensorValueMapping for the
GYRO_G&A
mode has list of integers forsourceValue
, and list of types fortype
. Something like this:{ "name": "Rate and Angle", "sourceValue": [0, 1], "type": ["int", "int"], "requiredMode": "GYRO-R&A", },
The problem here is I don't see a way in liquid template syntax to test if a value is a scalar or a list. (@WasabiFan, do you?) So there is no way to process this specification.
-
Change all the definitions in specialSensorTypes to have lists for both
sourceValue
andtype
. Then, if the list is of length one, do the current thing and return a scalar, and otherwise construct and return a tuple. This I think is doable but requires too much change for a single use-case (so far?). -
I could rewrite liquid template for special classes to leave the class declaration unclosed (omit the closing brace) and add the implementation of
gyro_rate_and_angle()
method manually. This will localize the change to this repo, but the source file will look slightly uglier.
@WasabiFan, @dlech, what do you think?
from ev3dev-lang-cpp.
I think it would make sense to be able to handle sensors with multiple values in a general case. There are a number of sensors that can return multiple values. So, make all sensors have "sourceValue" array. Most will just have length of 1, but that is OK.
from ev3dev-lang-cpp.
@dsharlet, what do you think of ev3dev/ev3dev-lang#169 and #11? It looks like this is not going to help much for this specific issue, especially since you are just using RATE
mode. What about the following idea: add an optional parameter set_mode=true
to the generated special sensor helper methods. So that
int r = s.rate();
will set the required mode and return the value, while
int r = s.rate(false);
would return the value immediately, without touching the mode. This way the user would be responsible for setting the correct mode, and the existing code would not need to be changed.
from ev3dev-lang-cpp.
That seems like a good idea, but then we need to make sure that it's clear what mode must be used. In this case, we would still need to change the getters to use the G&A mode to make this work, I think.
from ev3dev-lang-cpp.
I think there are two issues here:
- G&A mode is not accessible. ev3dev/ev3dev-lang#169 should solve that.
- When mode is set too often, there is a
std::system_error: Connection timed out
exception. #12 is for this case.
from ev3dev-lang-cpp.
There are two issues, but they're closely related; each requires the other to be fixed in order to be of use AFAIK. If the getters here still use their individual modes, you won't be able to get both rate and angle in a loop, regardless of whether or not you are telling it to set the mode: each call would require that you switched it to make it function. Am I misunderstanding?
from ev3dev-lang-cpp.
If you need both rate and angle, you would use the rate_and_angle()
function. This does not require changing modes between calls:
int rate, angle;
std::tie(rate, angle) = s.rate_and_angle();
this would also work with s.rate_and_angle(false)
given that you called this function at least once with set_mode=true
.
from ev3dev-lang-cpp.
Sorry for the delayed reply, I was missing the notifications for updates to this issue.
I think the mentioned PRs are an improvement, and they definitely solve both problems I had. Thanks for addressing them!
from ev3dev-lang-cpp.
Merged #12, waiting for @WasabiFan's approval on ev3dev/ev3dev-lang#169 to merge #11.
from ev3dev-lang-cpp.
from ev3dev-lang-cpp.
Related Issues (20)
- Cannot compile library on brick HOT 3
- Cross Compiling on Windows command not working HOT 7
- ev3dev-lang-cpp ready for ev3dev-stretch ? HOT 5
- Access file as quickly as possible HOT 19
- Problem to run a simple motor program HOT 2
- CMakeLists.txt forces C++11, breaking C++14 projects wanting to include it HOT 2
- Problem with pthread_xxx code (version GLIBCXX_3.4.21 not found) HOT 4
- What i should do with these files? HOT 1
- Mindstorms freezes while doing apt-get update HOT 2
- Connecting two large EV3 motors HOT 14
- Would you be interested in working UTs which could be run on host system? HOT 1
- What happened to Carlson Minot? HOT 4
- can't install gcc-5/unstable
- Python bindings seem to be faster than CPP for `infrared_sensor.proximity()` or `touch_sensor.is_pressed()` HOT 4
- Multiple definitions of symbols when linking HOT 1
- small question about polarity and speed_sp values on a motor HOT 1
- Support for bluetooth connections?
- Step 7, installing the librarys, doesnt work anymore. HOT 3
- Step 7 gcc compiler doesnt exist HOT 12
- Installation unter Windows 11 schlägt fehlt, Package kann nicht gefunden werden
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-cpp.