The PhotonVision NetworkTable doesn’t allow LabView users to access the data of multiple targets. has anyone created a workaround for this problem or have any ideas/suggestions to doing this
This decoding of the rawBytes key is normally done with a library like PhotonLib. LabVIEW doesn’t have a PhotonLib library. If there is demand for one it could probably be made, but unlikely to be soon.
If you want to do this yourself you can see the Java code above is decoding the rawBytes packet. LabVIEW has several VI’s built in for byte conversion like String to Byte Array. I don’t have a computer with a LabVIEW install, PhotonVision, and a robot handy so I can’t really put together a demo. Do you think you can record some of the data you are seeing and see if we can make sense of it?
Here’s a C++ example of the byte-packed struct. Strings are just character (byte) arrays, so that seems promising.
struct Packet {
double latency;
char targetCount;
Target target[targetCount];
};
struct Target {
double yaw;
double pitch;
double area;
double skew;
double x;
double y;
double r;
double cx1; double cy1; // Corners, repeats 4x
double cx2; double cy2;
double cx3; double cy3;
double cx4; double cy4;
};
I don’t know labview, but it should be possible to implement this yourself.
On first glance, It does appear that this could be decoded in LabVIEW.
The photonlib reference above appears to point to a read-only archived repository?
Some other things I gleaned quickly from the code
It appears the space occupied by the data types is as follows. (It used to that not all C types used the same spaced depending on the OS and compiler.)
- byte - 1 byte (I8)
- int - 4 bytes (I32)
- double - 8 bytes (dbl)
PhotonCamera seems to contain the names of the network table variables. It appears that they are:
rawBytes
driverMode
inputSaveImgCmd
outputSaveImgCmd
pipelineIndex
ledMode
version
prefixed by
/photonvision//
where
is the string name of the particular camera
if photolib was ported to LabVIEW do you think the creators would host it with the other code in the repository?
Attached is a zip file with a LabVIEW library that might decode the packet.
PhotonVisionLibLabVIEW.zip (64.8 KB)
Add the library file to your robot project and call “PhotonCamera_GetLatestResult”. Pass it the camera name. It returns a cluster with the data.
Here is the cluster
Use the cluster unpack and array index functions to get individual pieces of data.
If there is interest I can continue to create the rest of the library.
Note that this version returns the POSE as individual X,Y,Rotation values. I could return a Pose, in the future but this library would need the LabVIEW trajectory and control library as a dependency.
Happy roboting.
There is interest, at least from me. We will be using PhotonVision with the SnakeEyes Pi Hat this year and getting all the info in LabView would be extremely helpful.
I’m not interested in POSE so if that’s all that would be added I think what you already posted would be sufficient for me.
Thanks for what you have done so far though.
Okay. Keep in mind I’ve done very little testing. If have issues send a picture of the byte stream data and the resulting cluster and I’ll see what I can do.
I started down the path of doing the entire photo lib. So far the photo camera is coded and most of the photon utils. This did need the geometry functions so for those having the trajectory / control lib will be a prerequisite to those functions compiling.
Thanks, I just started looking at the photonlib libarary and methods like “calculateDistanceToTargetMeters” would be very useful so your work is much appreciated.
Wow this is amazing thank you so much for this its very helpful. Also did you make this yourself?
You’re welcome. And yes, I did write it myself. Programming, regardless of the languages, gets more familiar after 40 years.
I just added a github repository with a more complete port of PhotonVisionLib for LabVIEW. It includes the “Util” routines, including “calculateDistanceToTarget”. (Because these routines use the WPILIB geometry routines, the LabVIEW trajectory/control lib is a prerequisite.) This is still a work in progress.
This looks like a great starting point. Thanks for your effort! Any noteworthy updates to the API for the new season we should be careful of?
We have added 3 new methods to photon lib and will soon be adding a robot pose estimator class.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.