c4ev3 / EV3-API

EV3-API for Programming the LEGO Mindstorms EV3 in C
http://c4ev3.github.io
GNU General Public License v2.0
71 stars 22 forks source link

There is no possible way of resetting the gyro sensor #25

Open Jensonbruins opened 5 years ago

dnlmlr commented 5 years ago

You can just save the value at the point where you would like to do a reset and then calculate the offset from that.

Jensonbruins commented 5 years ago

Yes you can, but i think there should be a function for doing so

dnlmlr commented 5 years ago

The problem here is that the functions for interacting with the sensors are basically just sending a command to the hardware and return the response of said hardware. This prevents us from modifying the returned data like the gyro sensor rotation. The value you get from readSensorValue is directly provided by the sensor.

Since I don't think it would be a good idea to start adding wrapper functions for specific sensors, the only way I can see this getting implemented inside the API is with a sensor command.

So if you are aware of a sensor command code that allows resetting, feel free to implement it and create a pull request. Or alternatively provide some info if you have seen it somewhere else. Still this would have to be implemented for the SetSensorMode function to stay consistant with the current API. To reset the values you would do something like SetSensorMode(GYRO_RST).

simonedegiacomi commented 5 years ago

You can reset the sensor switching back and forth from angle to rate mode. I found this reading the implementation used in lejos and confirmed it from my experiments. I implemented it in my fork and the code to reset the sensor is already present in this pull request: https://github.com/c4ev3/EV3-API/pull/22