Hello!
As I am working on a VEXCode odometry tutorial, that may be published later on, and I am stuck with one major issue. I am simulating my code utilizing lua, and I have the ability to utilize:
local m = wait(time)
And I cannot figure out how to do the same thing with waiting/sleeping in a VEXCode task. I am looking for a wait that, when called, returns the actual value the robot has waited for to make calculations slightly more precise based upon time by doing:
worldX += XVelocityWorldSpace * (m/time)
Is there anything I can utilize that allows waiting to return the actual time waited, or would I have to deal with the slight time error from the statement?
Note: By utilizing such a statement it improved the odom position accuracy from 95% to 99%, and it would be awesome if theres a way to do this in vexcode
and for odometry, checkout the recent timestamp() addition to all device classes in VEXcode that returns the time when the last message (and therefore position etc.) was received from any smart device.
@jpearman Would it be possible to have the function addded to the VEXCode api: https://api.vexcode.cloud/v5/html/index.html
The timestamp function seems awesome, but I cannot find how to use it or where to find it, even when looking on the VEXCode command reference. Are any examples available?
PS: Thank you so much for the help!
No, that’s the C API (which I guess you could use) but something like this is more appropriate.
If you had an inertial sensor
vex::inertial imu(PORT1);
then you can get the time the last data was received as
uint32_t t = imu.timestamp();
and yes, you could substitute int (or unsigned int more accurately) where I used uint32_t, it’s just habit that I tend to do that.
timestamp() is available for all smart port sensors (except vision sensor because it didn’t make much sense for that and there are some implementation issues). For three wire devices (quad encoder etc.) you need to use it on the base three wire device, so the Brain.ThreeWirePort for the internal port.
timestamp() only has mS accuracy
yea, new classes and their member functions will be added to the documentation soon, these new features were only released a few days ago as part of the 2.0 preview.