-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed setPose #15
base: master
Are you sure you want to change the base?
Fixed setPose #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks @Sparib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using setpose has always been confusing, this makes a lot more sense to me.
The first point is just something that my team and our sister-team overlooked, the second point it the good stuff.
The Origins
I have been working with ftc265 for a while and encountered numerous errors and weird things when it came to using the
setPose
function. I believe I have found the problems, sources of the error, and the fixes for them.1)
setPose
is weird.The reason that sometimes
setPose
doesn't work if you do it too quickly after initialization is as follows:The camera begins initialization at
new T265Camera()
.Then,
setPose
is ran, but initialization isn't complete, sosetPose
defaults to usingnew Pose2d()
as the "origin"for translation.
Then, the camera fully initializes and whatever the position it started at is used, with the incorrect offset from
setPose
.Example:
(Where there is something that looks like
(0,0)
, it means(x,y)
. I ignore rotation for simplicity's sake, but itacts the same)
Initialization begins
setPose(0,0)
is ranCamera gives a reference of
(0,0)
because it has yet to initialize fullyThe offset is none because the origin and new pose for
setPose
were the sameThe camera fully initializes at a position of
(10,2)
and that is passed to the program because there is no offset.The Fix:
Wait until
getLastReceivedUpdate()
returns actual numbers and not just(0,0)
, that waysetPose
has actual valuesto calculate off.
2)
setPose
is broken.I have no idea how no one has noticed this and asked about it or even explored it for themselves, as I did, but I have
found that the
setPose
function is truly broken.The reason that
setPose()
does weird things when you try to use it multiple times is because it uses the translatedposition in the offset calculation instead of the camera's position
That makes no sense so,
Explanation:
There are 4 values in this example
Also, something like
(x1,y1) - (x2,y2)
is the same as(x1-x2, y1-y2)
. The same goes when using names instead of numbers.The way the camera currently works is that
Offset Pos
is calculated by doing(New Pos) - (Trans Pos)
.This poses problems.
Given:
If we then set
New Pos
to be(0,0)
, then the values change to be:This is normal!
However, if you then set
New Pos
to be(0,0)
again, then the calculation is done with the translated pos causingthe offset to go back to
(0,0)
because(New Pos) - (Trans Pos) = (0,0)
, which gives this:Therefore,
setPose
is broken in the library.The fix:
If the camera instead calculates
Offset Pos
by doing(New Pos) - (Camera Pos)
, we get what we want, always making(Trans Pos) = (New Pos)
whenNew Pos
is changed.These example take place in a world where the camera stays perfectly still. If you introduce movement, the calculations
get even more broken.
Example for fun :P
Run
setPose(0,0)
and you get:Then, move the camera by
(+2, -1)
and the values become:Try doing
setPose(0,0)
again, and offset is calculated(New Pos) - (Trans Pos) = (Offset Pos)
, or(0,0) - (2,-1) = (-2,1)
, making the values aftersetPose
:With
Trans Pos
not being(0,0)
this concludes thatsetPose
is fundamentally broken.My edits:
I added a variable called
mLastRecievedCameraUpdate
(spelled incorrectly to match the incorrect spelling ofmLastRecievedCameraUpdate
) here.I also added a consumer for that variable called
cameraConsumer
here.I then created a new function called
consumeCameraUpdate
which takes the same parameters asconsumePoseUpdate
here, and that is called by the C++ file (here).After being called it passes all of its arguments to
consumeCameraUpdate
, which I will probably soon change to it passing the pose instead ofx
,y
, andradians
.The final modification was making
setPose
usemLastRecievedCameraUpdate
instead ofmLastRecievedUpdate
(here).mLastRecievedCameraUpdate
is not meant to be sent to the end user, thus the absence of any getter function.