View Single Post
  #3   Spotlight this post!  
Unread 17-12-2012, 18:06
Michael_Lee Michael_Lee is offline
Registered User
FRC #2976
 
Join Date: Jan 2012
Location: Issaquah, WA
Posts: 21
Michael_Lee is an unknown quantity at this point
Re: Communicating with the robot via Python?

But how? I first tried copying the contents of the site-packages folder from robotpy so my client-side folder structure looked like this:
  • my_code.py
  • robotpy
    • wpilib
      • __init__.py
      • Buttons.py
      • Commands.py
      • core.py
      • NetworkTables.py
      • Preferences.py
      • SmartDashboard.py
    • _nivision.pyd
    • _vision.pyd
    • _vision2009.pyd
    • _wpilib.pyd
    • nivision.py
    • README
    • sip.pyd
    • vision.py
    • vision2009.py

This failed, and gave the following stack trace:

Code:
Traceback (most recent call last):
  File ".\my_code.py", line 14, in <module>
    main()
  File ".\my_code.py", line 4, in main
    table = robotpy.wpilib.NetworkTable.GetTable(tableName)
AttributeError: 'module' object has no attribute 'wpilib'
I'm assuming that I'm setting up robotpy on the client end incorrectly. Am I supposed to copy the contents to my local site-packages folder? Or does robotpy come bundled with a python interpreter? If so, where can I find it?

----

Also, although I wasn't able to test this, this is the code I came up with. I'm basically trying to send data from my laptop to the computer, and confirm I received it on the robot by mirroring it to the SmartDashboard. Do I understand how to use robotpy and NetworkTables correctly? Are there any changes I should make?

my_code.py:

Code:
import robotpy

def main(tablename = "testTable"):
    table = robotpy.wpilib.NetworkTable.GetTable(tableName)
    while True:
        test_int = int(raw_input("Test int:"))
        test_string = raw_input("Test string:")
        table.BeginTransaction()
        table.PutInt("testInt", test_int)
        table.PutString("testString", test_string)
        table.EndTransaction()
        
if __name__ == '__main__':
    main()
The code on the robot (in C++):

Code:
// snip

void MainRobot::OperatorControl(void) {
    NetworkTable *table = NetworkTable::GetTable("testTable");
    SmartDashboard *s = SmartDashboard::GetInstance();
    
    while (IsOperatorControl()) {
        table->BeginTransaction();
        int testInt = table->GetInt("testInt");
        std::string testString = table->GetString("testString");
        table->EndTransaction();
	
        
        s->Log(testInt, "testInt");
        s->Log(testString.c_str(), "testString");
    }
}
----

Also, the C# sample code I was looking through gave this:
(from http://www.chiefdelphi.com/forums/sh...d.php?t=103352)

Code:
// 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();
However, while looking through the robotpy source code, I was unable to find a "setIPAddress" method in the NetworkTable class. Do I need this method? If so, where is it?
Reply With Quote