Open Jensonbruins opened 5 years ago
Yes you can, but i think there should be a function for doing so
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)
.
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
You can just save the value at the point where you would like to do a reset and then calculate the offset from that.