Problems while scripting

Hello!
I’m still using a poppy image and i’m currently testing some python code with nosetests, but when i test i have often an error in the Thread-1 when creating a PoppyErgoJr.
I used ‘fuser /dev/ttyAMA0’ and it said the port is unused.
What does exactly check the Thread-1?
It will make my tests easier if i understand this one.

Unused or already used ?
Can you paste the error message and the command which raise the error. It coulb be because you try to instanciate a new robot and you didn’t close a previous one.

The error message is “Setup failed, see Thread-1 Tracebackfor details”.


It happened with this script(i took a simple script):

import unittest
from Projet.bras_support.lock import Lock
from poppy.creatures import PoppyErgoJr
import time

class TddLockTest(unittest.TestCase):
def setUp(self):

    self.locker=Lock()
    self.poppy=PoppyErgoJr(camera='dummy')
    self.motor=self.poppy.m6
def tearDown(self):
    time.sleep(0.2)
    self.poppy.close()
def test_free_motor_chosen(self):
    self.locker.unlock(self.motor)
    check=self.locker.getCompliant(self.motor)
    self.assertTrue(check)

And here is the locker:

import pypot.dynamixel

class Lock(object):
def getCompliant(self,motor):
if isinstance(motor, pypot.dynamixel.motor.DxlXL320Motor):
return motor.compliant
else:
raise TypeError
def unlock(self,motor):
if isinstance(motor, pypot.dynamixel.motor.DxlXL320Motor):
motor.compliant=True
else:
raise TypeError
def lock(self,motor):
if isinstance(motor, pypot.dynamixel.motor.DxlXL320Motor):
motor.compliant=False
else:
raise TypeError

And there is fuser:
I do it to check if something is still using the port, but i dont know if it helps in this situation.

My main problem is that i dont always have the Thread-1 error, sometimes my test runs normally and i dont understand how to be sure that Thread-1 isnt a problem.

edit: i dont have indent problems, but the poppy forum doesnt show indents as they are

It could be better to install pypot >3 an use pypot.creatures, because your install could miss some important updates.

Is the following code raising an error ?
> from poppy.creatures import PoppyErgoJr

for i in range(3):
    print('test : {}'.format(i))
    robot = PoppyErgoJr(camera='dummy')
    robot.m1.compliant = False
    robot.m1.compliant = True
    time.sleep(0.5)
    robot.close()
    time.sleep(5)

Once i added “import time”, i ran this 10 times in terminal and 3 times in jupyter without any error.

Means your robot is working like a charm. You didn’t do anything else in your code than open, test compliance and close. So I can’t understand the cause of your error. One possibilty is that your tests are running to quiclky and you try to open of new robot before the previous one was complety close -> time.sleep(4)

You can also try a pypot.close_all connections() (search the doc. I’m not sure where is this function…) to be sure all connections are cleanly close.

Probably TddLockTest(unittest.TestCase) do something not allowed by the robot. I can’t see anything else than doing a step by step debugging. Maybe someone on this forum have other ideas.

Thank you, it seems that with some time.sleep added, the “Thread-1 error” doesnt appear again. However i cant be sure that the thread-1 interrupts my program only when i give orders too quickly. It can be interesting to have an explanation from the poppy team about how this thread works to understand it clearly.

Thread-1 is just the first thread launch by python. This is the thread where initialisation of your robot is launched and in your case it is a ping on all motors to check the answer. Thread-1 error interrupt the communication with the robot. Maybe not your program but sure your tests will all fail.

if you are interested you can find the source code in pypot.dynamixel.io

My bad, due to the fact that this error happened to me only when using a poppy robot, i didnt realize that it could be just a python error. I’ll check it in pypot.