FRC125 / NU16

Official code repository for the NUTRONS 2016 robot
http://nutrons.com
4 stars 3 forks source link

Coprocessor Communication #32

Closed ashergottlieb closed 8 years ago

ashergottlieb commented 8 years ago

I created a DataController class which can be used to interface with the coprocessor through networktables, but I don't know if my implementation of it was the best. Currently, you tell the DataController to start requesting vision information of a certain type, and the DataController uses another class that runs concurrently to request that information from the coprocessor, and update the DataController's own instance variables (currently it accesses them directly, which I should change). You can then use DataController's methods to get those variables, and it will throw an exception if the data is too old, (the expiration time is set by the constructor or a method parameter). This doesn't seem like the best way to implement this, so if anyone knows of a better design pattern, please let me know!

camilo86 commented 8 years ago

We already have that. We have a small camera class that can get sample info from the camera. Feel free add more features to it if yo think we need it https://raw.githubusercontent.com/FRC125/NU16/master/src/com/nutrons/lib/utils/Camera.java

ashergottlieb commented 8 years ago

Oh, I didn't notice that. I created a networktables branch where the DataController is. The only problem with the Camera class is that we need to be able to request which data from the coprocessor we want (to process slightly faster), and know when it has been updated, so that the Robot doesn't try to process old information.

Say it takes 1 second to process the image, and the coprocessor just started to process an image when the RoboRIO requests different data, now it could take up to 2 seconds before the RoboRIO gets a response with the correct information. We don't want the Robot to act on old, incorrect information, and we want it to know when the new data arrives.

The DataController class solves this by setting up a networktables variable to specify the type of information to be updated by the coprocessor, and the updateInProgress boolean is set to true to request the data. The coprocessor sets updateInProgress to false once it updates the networktables, and the RoboRIO reads the new information. We obviously have to handle this with something running concurrently, which the DataController helps do.

I don't know if the way I implemented DataController is the best way to solve this problem, however, by throwing exceptions if the Data is expired. Take a look at it to see what I mean: https://github.com/FRC125/NU16/tree/networktables/src/com/nutrons/stronghold/networktables

camilo86 commented 8 years ago

There will be a known constant that will be set when the Camera is not in used. This way, when we require camera information, we can ignore such constant until we get a real value out of the beaglebone. Thats probably an easier fix to having a 'flag' boolean

camilo86 commented 8 years ago

such implementation is not in the Camera class yet since the constant is yet to be defined. Once we know what value we can consider our "ignore value" we can implement that

ashergottlieb commented 8 years ago

How will we ignore that value? That's the question I'm wondering. In the Camera class, will getDistanceToTargetInFeet() throw an exception if it is invoked when the beaglebone gives an "ignore value"? I assume we don't want to have the class that invokes getDistanceToTargetInFeet() to have to deal with that "ignore value," and we'd want the Camera class to handle it.

I think we would want to avoid exceptions, but leaving the class that invokes getDistanceToTargetInFeet() to deal with the ignore value also seems like bad design... how would you approach this?

I also already setup code for the 'flag' boolean in DataController, it wasn't hard to implement and probably wont be in python either.