|
Dear Tar,
It is me again. We su
ccessfully send data to NAO via NAO.NET however since we send it each 1 sec from Kinect-enabled application the latency of NAO reaction is visible. Each time when I want to send parameters to function RHandMove in a scriptName - The script should be open and close. And thus each 1 sec, which delay the whole program.
Can I open the script at the begging and sends parameters only to function and close at the end of Kinect session? I tried in clsConection to open only the file but it gave errors.
We use the ExFile like this
callResult = clsConnection.ExFile("D:/PythonProjects/" + scriptName, angles.RShoulderPitch.ToString() + ... +IP_NAO);
The function is
def RHandMove(robotIP,PORT,Angle1,Angle2,Angle3,Angle4,Angle5,Angle6):
thank you,
Anna
|
|
|
|
|
Thank you for using my program and your success to execute it correctly ,
In the beginning
As you know , the program works like a .NET layer to execute and python file as new process.
so this takes time to create a new process and pass parameters ,then wait until python executes and return success code ,
also if you use the XML feedback it will take more time to read the actual values from the robot after move.
but fortunately this issue i resolved by a workaround way which is creating a new thread for every call
so you can simply not use one call and give many parameters to do.
but call the method several times so they will execute together and wait for each call (to avoid overlap call) because this may cause of your robot damage.
as the example show , it open both hands together
I hope listen from you soon ,
Tareq Gamal.
Wellcome
|
|
|
|
|
Dear Tareq,
It is so nice there are people like you to help us in bottleneck situations.
My problem is the following, I want only to run Python code from C# WPF project. In C# application I define the names of joints, time and calculate angles for Nao. I generate the Python code here, as well. How can I use your dll, because you explain in the project movie we have to create a project DLL to interact with Python .NET
Where I have to write the script
myProcess.StartInfo.FileName = fileName; //This is python File Name
myProcess.StartInfo.CreateNoWindow = true;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.Start();
I will appreciate if you show me step by step the solution.
I have Visual Studio 2013 and Python 2.7
Thank you,
Anna
|
|
|
|
|
Thank you Anna for this introduction
So in the beging I will exceplain to you how it works:
I dont like the code by python as i want to use the nao in my .NET application
- Give him commands .
- Execute .
- (Optional ) Give me the feed back after execution like in the Example.
WE can call this solution like 3 layers solution .
1st layer is the python
2nd layer is the Interface
3rd layer is your application.
1st of all we have our own VS program layer 3 for our Solution
you will add more 2 projects ,
- First layer is the Python code files which interact with the robot already
(I created a project for them in VS but if you have it as separated files no problem to skip this project)
The simpliest way to use this code is
adjusting Python files by a way to just execute the commands with parameters
Because we will pass these parameters from our .NET program.
- Second layer is the interface between your windows Application and the Python Code files
it is DLL to make easy for maintain and reusability ,
so the main function for this DLL is taking the Functions and commands , like moveto ( x,y )
So Here we have 2 things:
- the Action ( MoveTo)
- and parameters ( x,y)
You have to have maping python file for these parameters mean :
You have to have file for moving and take the 2 parameters .., like in the video .
------------
This code and parameters in the place you mention in your message.
in the DLL
calling the file in separated process to free the processor for your presentation later and your program
so it create a separated process for this objective and following up with it.,
-------------
Back to your code (your application you are developing ) Layer three
just reference to this DLL in your project references ,
then call the methods as you need
So simply the sequence :
your code-> dll ( create process and pass it)-> python files
Until this point the code will work perfectly you can stop here.
But if you need the feed back after execute :
Moved ? what is the new X,Y , like this info
then I created just a module as XML file to write Whatever you like at the python environment
then Read it after executing so .NET will know what is going on
It is in the article .
So its sequence :
Python execute code-> Write feedback XML-> Dll Read the XML-> return it to your application
|
|
|
|
|
Thank you Tar,
I’ve tried to run your demo and unfortunately I have got the following exception in frmMove.cs:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in dllPython.NETConnection.dll
Additional information: The system cannot find the file specified
System.ComponentModel.Win32Exception was unhandled
HResult=-2147467259
Message=The system cannot find the file specified
Source=dllPython.NETConnection
ErrorCode=-2147467259
NativeErrorCode=2
StackTrace:
at dllPython.NETConnection.NAO.clsHead.MoveTo(Double x, Double y)
at NAO.NET.frmMove.<>c__DisplayClasse.<btnmovehead_click>b__0() in d:\NAO.NET\NNet_demo\NAO.NET\frmMove.cs:line 72
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
I have NAO connected with IP address (and changed in the config file) and reference file dllPython.NETConnection added in the C project, console application, .NET framework 4.5
Thank you
Anna
|
|
|
|
|
This is great step ,
this is a method a fast demo for the generic method : ExFile to run this demo you have to put files and set parameters in place:
file called clsHead.py , at this relative path:
static public int MoveTo(double x, double y)
{
try
{
return clsConnection.ExFile("v1\\clsHead.py", clsDefinitions.RobotIP + " " + x.ToString() + " " + y.ToString());
}
}
you can use but you have to place a python file to the place in the method
for generic use you have to use the method :
public static int ExFile(string FileName, string Arguments)
Tell me if you have any troubles.
Wellcome
|
|
|
|
|
Dear Tar,
We made the second great step - we open and close the NAO hands through NAO.NET, however:
1. We couldn’t pass parameters to Python script, we run a script but explicitly set in it the IP, port, a joint and an angle. We couldn’t import clsFile in the script, where it is? And consequently we had an error in all lines with clsFile.clsFile.logInFile(…) We put your dll in the Pythonpath in the SystemVariables.
2. We add the class clsConnection to our project but we couldn’t read the PythonWorking dir in ExFile. It is null. We add to the filename in ExFile the path to the python script.
3. We comment lines 67 and 68 in the class frmMove (an acess to xml files) because it gave an exception:
System.IO.FileNotFoundException was unhandled by user code
HResult=-2147024894
Message=XML file not found
Source=dllPython.NETConnection
StackTrace:
at dllPython.NETConnection.Config.clsXMLValues.GetNAOValue(String ItemName)
at NAO.NET.frmMove.<btnapply_click>b__1f() in d:\NAO.NET\NNet_demo\NAO.NET\MoveHands.cs:line 71
InnerException:
We made all LiveNAO directories. Where the config file should be placed?
Best
Anna
|
|
|
|
|
Dear Anna ,
Thank you for your feedback
sorry for late , But I was going to double check the path for you,
So the Config File's Path is :
C:\LiveNAO\Config\
Wellcome
|
|
|
|
|
Thankyou Tar,
what about the clsStatics and clasFile modules?
Python script gave this error:
import clsStatics
ImportError: No module named clsStatics
Anna
|
|
|
|
|
Thank you Tar,
what about the clsStatics and clasFile modules?
Python script gave this error:
import clsStatics
ImportError: No module named clsStatics
Anna
|
|
|
|
|
drag them in your python files:
clsFile.py :
import os
from clsStatics import clsStatics
import io
#import time
import datetime
class clsFile(object):
"""description of class"""
@staticmethod
def logInFile(data):
if not os.path.exists(clsStatics.localLogs ):
os.makedirs(clsStatics.localLogs)
file = open(clsStatics.localLogs+str(datetime.date.today())+'.txt','a')
file.writelines(str(datetime.datetime.now()) +' - '+ data)
clsFile.logInFile('Data in the LogFile')
clsStatics.py:
import ConfigParser
#from IPython.config.loader import Config
class clsStatics(object):
DataLoaded = False
Config = ConfigParser.ConfigParser()
"""description of class"""
########### NAO Settings :
#RobotIP=""
#RobotPort= 0
#RobotLoginName = ""
#RobotLoginPassword = ""
############# End Robot Settings
#RobotLanguage = ""
## database Settings :
#dbServerName = ""
#dbusername=""
#dbpassword = ""
#dbdatabasename = ""
#dbportnumber = 0
##localLogs = ''
#recordFolder = ""
#negativePath = ""
#positivePath = ""
#ocvImage =""
#Could not create a proxy, as there is no current broker in Python's world.'
@staticmethod
def _loadIni():
clsStatics.Config.read("C:\\LiveNAO\\Config\\config.ini")
#clsStatics. Config.sections().append('Globals')
#clsStatics. Config.sections().append('LocalFiles')
#['Globals', 'LocalFiles', 'Database', 'Robot','Others']
@staticmethod
def GetiniValue(Section,Option):
try:
Value = clsStatics.Config.get(Section,Option)
except:
print("exception on %s!" % option)
return Value
@staticmethod
def _loadValuesFromini():
try:
########### NAO Settings :
#[Robot] Section
clsStatics.RobotIP=clsStatics.GetiniValue("Robot","RobotIP")
clsStatics.RobotPort = int(clsStatics.GetiniValue("Robot","RobotPort"))
clsStatics.RobotLoginName = clsStatics.GetiniValue("Robot","RobotLoginName")
clsStatics.RobotLoginPassword = clsStatics.GetiniValue("Robot","RobotLoginPassword")
clsStatics.recordFolder = clsStatics.GetiniValue("Robot","recordFolder")
clsStatics.RobotLanguage = clsStatics.GetiniValue("Robot","RobotLanguage")
############ End Robot Settings
# database Settings :
#[Database]
clsStatics.dbServerName =clsStatics.GetiniValue("Database","dbServerName")
clsStatics.dbusername=clsStatics.GetiniValue("Database","dbusername")
clsStatics.dbpassword = clsStatics.GetiniValue("Database","dbpassword")
clsStatics.dbdatabasename = clsStatics.GetiniValue("Database","dbdatabasename")
clsStatics.dbportnumber = int(clsStatics.GetiniValue("Database","dbportnumber"))
#[LocalFiles]
clsStatics.localLogs = clsStatics.GetiniValue("LocalFiles","localLogs")
clsStatics.negativePath = clsStatics.GetiniValue("LocalFiles","localLogs")
clsStatics.positivePath = clsStatics.GetiniValue("LocalFiles","localLogs")
clsStatics.xmlfile =clsStatics.GetiniValue("LocalFiles","xmlFile")
clsStatics.ocvImage =clsStatics.GetiniValue("LocalFiles","localLogs")
print "Values Loaded Successfully"
clsStatics.DataLoaded = True
except:
print "Error while loading Values! "
clsStatics._loadIni()
clsStatics._loadValuesFromini()
Wellcome
|
|
|
|
|
Dear Tar,
Thank you again for your help and for the recent efforts to write for us the python scripts slsFile and clsStatics. Unfortunately, we could run the robot with the IP in the config.ini file so we pass IProbot as argument too:
For those who is going to struggle with all this, we are going to share our solution
We use the ExFile like this
callResult = clsConnection.ExFile("D:/PythonProjects/" + scriptName, angles.RShoulderPitch.ToString() + " " + angles.RShoulderRoll.ToString() + " " + angles.RElbowYaw.ToString() + " " + angles.RElbowRoll.ToString() + " " + angles.RWristYaw.ToString() + " " + angles.RHand.ToString() + " " +IP_NAO);
And one of our python scripts MoveRHand.py is:
import time
import sys
from naoqi import ALProxy
def RHandMove(robotIP,PORT,Angle1,Angle2,Angle3,Angle4,Angle5,Angle6):
motionProxy = ALProxy("ALMotion", robotIP, PORT)
ttsProxy=ALProxy("ALTextToSpeech", robotIP, PORT)
postureProxy=ALProxy("ALRobotPosture", robotIP, PORT)
postureProxy.goToPosture("StandInit", 0.5)
ttsProxy.say("I am Robi! Lets play! ")
time.sleep(2.0)
motionProxy.setStiffnesses("RShoulderPitch", 0.5)
motionProxy.setStiffnesses("RShoulderRoll", 0.5)
motionProxy.setStiffnesses("RElbowYaw", 0.5)
motionProxy.setStiffnesses("RElbowRoll", 0.5)
motionProxy.setStiffnesses("RWristYaw", 0.5)
motionProxy.setStiffnesses("RHand", 0.5)
names = ["RShoulderPitch","RShoulderRoll","RElbowYaw","RElbowRoll","RWristYaw","RHand"]
angles = [Angle1,Angle2,Angle3,Angle4,Angle5,Angle6]
fractionMaxSpeed = 0.2
motionProxy.setAngles(names, angles, fractionMaxSpeed)
time.sleep(3.0)
motionProxy.rest()
if __name__ == "__main__":
if len(sys.argv) > 1:
Angle1 = float(sys.argv[1])
Angle2 = float(sys.argv[2])
Angle3 = float(sys.argv[3])
Angle4 = float(sys.argv[4])
Angle5 = float(sys.argv[5])
Angle6 = float(sys.argv[6])
robotIP = sys.argv[7]
RHandMove(robotIP,9559,Angle1,Angle2,Angle3,Angle4,Angle5,Angle6)
Thanks again
Wish you all best
Anna
www.iser.bas.bg/metemss
|
|
|
|
|
Dear ,
for Advanced Moves , you have to make all logic at the Python file then pass it to the .NET Application.
- the delay is logical because your code go throw many steps :
1- Computer ,(as its specs)
2 - Compile by .NET
3- send command to python compiler
4- Python Send it to NAO Robot.
5- NAO compile and Execute.
----------------
if you add the feed back it will delay more time because : this part steps :
6- robot make XML result code by read the motors new angle from the robot which May be not the same 100% as what you sent because of NAO motors accuracy.
-This XML sent to your Computer Hard drive.
- your program read the XML file.
-------------
all of this steps take time.
you can decrees the time by write multi-steps in Python code once.
Wellcome
|
|
|
|
|
|
you are welcome
Wellcome
|
|
|
|
|
Good Article .. My vote of 5
|
|
|
|
|
Dear aarif ,
Thank you very much for your vote,
Which part you liked?
If you have any questions just ask..
|
|
|
|
|