roboticslab-uc3m / xgnitive

Research on algorithms for Continuous Goal-Directed Actions (CGDA), Robot Imagination System (RIS)...
http://robots.uc3m.es/dox-xgnitive/
GNU Lesser General Public License v2.1
5 stars 1 forks source link

yarp rpc /teoSim/rightArm/rpc:i "get encs" responsing with complex format #43

Closed RaulFdzbis closed 7 years ago

RaulFdzbis commented 7 years ago

When trying to get the state of the encoders from TEO, the output format is something like this.

yarp rpc /teoSim/rightArm/rpc:i
>>get encs
Response: [is] encs (30.0 0.0 0.0 0.0 0.0 0.0) [tsta] 70 1508927958.17612 [ok]

When trying to parse that string in python to get the state of each encoders things are not so straightforward as i think should be. With the following code:

for i in range(self.res.size()):
    state_now.append(self.res.get(i).asDouble())
print("The state now is: ",state_now)

I get the following output:

The state now is:  [29545.0, 0.0, 0.0, 1635021684.0, 89.0, 1508928750.360022, 27503.0]

I think there is a problem with the formatting of the ouput signal. To solve this I did the following:

response=self.res.toString()
response = response.replace("(", "") #Delete parenthesis from the string
response=response.split(" ") #split string
print("response2: ",response[2]) 

With the output:

response2:  30.0

So I think that a possible improvement for the future could be to change the format of the output of "get encs" to have a more proper format.

jgvictores commented 7 years ago

Better use the IEncoders interface: see example.

jgvictores commented 7 years ago

PS: Parsing [is] encs (30.0 0.0 0.0 0.0 0.0 0.0) [tsta] 70 1508927958.17612 [ok] would be a bit more like (note that syntax may be slightly different, do not have ipython right now):

b = self.res.get(2).asList()

and then doing similar to yours:

for i in range(b.size()):
    state_now.append(b.get(i).asDouble())
print("The state now is: ",state_now)
RaulFdzbis commented 7 years ago

Thank you @jgvictores!

I used IEncoders as you suggested in the code.

jgvictores commented 7 years ago

Regarding these lines that are currently:

        state_now=[]
        state_now.append(float(str(v[0])))
        state_now.append(float(str(v[1])))
        state_now.append(float(str(v[3])))

Since str is just for printing, maybe they could be more efficiently implemented as:

        state_now=[]
        state_now.append(v[0])
        state_now.append(v[1])
        state_now.append(v[3])

PS: Also careful with more get encs along the same code.

RaulFdzbis commented 7 years ago

BTW:

Confirmed this works:

b = self.res.get(2).asList()

for i in range(b.size()): state_now.append(b.get(i).asDouble()) print("The state now is: ",state_now)

Thank you @jgvictores i think we can close this issue.