|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Raspberry Pi as Coprocessor
We plan on using the Raspberry Pi to do our vision processing. How would we output Python script results (after processing) and receive on RoboRio (Java)? I looked into pynetworktables and am confused on how to receive the data from the RoboRio.
|
|
#2
|
||||
|
||||
|
Re: Raspberry Pi as Coprocessor
GRIP has some examples. Specifically samples/frc_find_red_areas.
Basically, you just publish your results to NetworkTables with the pi connected to the roborio/radio/switch with an ethernet cable, then you can read that from your robot program. |
|
#3
|
|||
|
|||
|
Re: Raspberry Pi as Coprocessor
Quote:
|
|
#4
|
||||
|
||||
|
Re: Raspberry Pi as Coprocessor
|
|
#5
|
|||
|
|||
|
Re: Raspberry Pi as Coprocessor
Quote:
Code:
//========================================
//Robot Code
// declare object
NetworkTable cameraTable;
// getinstance (table is a singleton, if one does not exist then one will
// be created otherwise returns reference to existing instance
cameraTable = NetworkTable.getTable("camera");
// get data element from the table
// default values returned if no data has been provided from another source yet
cameraTable.beginTransaction();
Boolean imageFound = cameraTable.getBoolean("found", false );
Double imageOffset = cameraTable.getDouble("offset", -1.0);
Double imageDistance = cameraTable.getDouble("distance", -1.0);
cameraTable.endTransaction();
System.out.println( "found = " + imageFound);
System.out.println( "offset = " + imageOffset);
System.out.println( "distance = " + imageDistance);
//=======================================
// Driver Station PC
// camera image processing is done in C# application on DS
// declare it
private NetworkTable table;
// Init NetworkTable
NetworkTable.setIPAddress("10.6.23.2"); // ip of crio
table = NetworkTable.getTable("camera");
// in the image processing loop
table.beginTransaction();
table.putBoolean("found", true);
table.putDouble("distance", distance);
table.putDouble("offset", offset);
table.endTransaction();
Looks like what I need, but is it missing something (ie setTeam, etc.)? |
|
#6
|
||||
|
||||
|
Re: Raspberry Pi as Coprocessor
That example is 4 years old. All you have to do on the pi:
Code:
NetworkTable.setClientMode();
NetworkTable.setTeamNumber(1512);
ITable visionTable = NetworkTable.getTable("vision");
Then to publish the results from the vision processing Code:
visionTable.putBoolean("Have target", haveTarget);
visionTable.putNumber("Angle to target", angleToTarget);
...
In your robot program, you'd also declare a table for vision just like we did on the pi. To read the values the pi is publishing, use the corresponding 'get' methods Code:
haveTarget = visionTable.getBoolean("Have target", false); // default to false
targetAngle = visionTable.getNumber("Angle to target", 0); // default to 0
...
|
|
#7
|
|||
|
|||
|
Re: Raspberry Pi as Coprocessor
Thank you so much!
|
|
#8
|
|||
|
|||
|
Quote:
Sent from my Pixel using Tapatalk |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|