Ask Your Question
0

Add StateMachine object in concurrent container

asked 2019-03-10 13:25:47 -0500

KeyKeyQ gravatar image

updated 2019-03-11 16:30:07 -0500

jayess gravatar image

Greetings,

I am currently trying to write a state machine with smach for a robot, including a safety fuction, where the activity of the robot should be preempted, once a specific message is sent to a certain topic. I tried to modify the example using monitor state and concurrent container: http://wiki.ros.org/mysmach/Tutorials... . My idea was to replace the FOO_CALC state with the state machine of my robot, that is nested in the concurrent container. My code reads as the following: https://github.com/Mrkeyiiii/ROS_Lear...

After rosrun one would get the following message: TypeError: 'StateMachine' object is not callable. I wonder whether there is any work-around for this problem?

PS: It's my first time to ask a question in this platform and I am not sure whether I am doing it correctly. Please let me know if there is anything that I could improve. Many thanks in advance!

Edited: Added error code:

[ERROR] [1552331031.713732]: Error raised during SMACH container construction: 
Traceback (most recent call last):

  File "/home/qi/catkin_ws/src/example0/src/safety.py", line 134, in main
    smach.Concurrence.add('FOO_CALC', sm_sub())
TypeError: 'StateMachine' object is not callable

Traceback (most recent call last):
  File "/home/qi/catkin_ws/src/example0/src/safety.py", line 150, in <module>
    main()
  File "/home/qi/catkin_ws/src/example0/src/safety.py", line 134, in main
    smach.Concurrence.add('FOO_CALC', sm_sub())
TypeError: 'StateMachine' object is not callable
edit retag flag offensive close merge delete

Comments

Can you please update your question with a copy and paste of the full error and your code?

jayess gravatar image jayess  ( 2019-03-10 15:26:35 -0500 )edit

Hi, thanks for your reply, please check the updated question :D

KeyKeyQ gravatar image KeyKeyQ  ( 2019-03-11 14:05:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-03-11 16:42:32 -0500

jayess gravatar image

updated 2019-03-11 16:43:01 -0500

You have code like this

sm_sub = smach.StateMachine(outcomes=['foo_succeeded','preempted']) # line 119

Here, sm_sub is an object and the interpreter is telling you that you can't call an object in the following error you posted

Traceback (most recent call last):

  File "/home/qi/catkin_ws/src/example0/src/safety.py", line 134, in main
    smach.Concurrence.add('FOO_CALC', sm_sub())
TypeError: 'StateMachine' object is not callable

In line 134, you're trying to call the sm_sub object, which the interpreter is saying you can't do:

smach.Concurrence.add('FOO_CALC', sm_sub()) # parentheses means you're calling a function

In the example that you linked to, I'm guessing that you're following this line

smach.Concurrence.add('FOO_CALC', foo())

Here, the author went against Python's conventions and named their class foo instead of Foo (notice the lack of a capital F in the first one). This can make things a little confusing if you're not reading carefully. The example is actually simultaneously creating an object of foo type and passing it to the add function.

So, what you probably need to do is pass the object sm_sub and not call it.

Try

smach.Concurrence.add('FOO_CALC', sm_sub) # no parentheses on sm_sub

instead and see if it works. Please note that I'm not familiar with this package, I'm just going off of the tutorial that you linked to, your posted error, and your posted code.

edit flag offensive delete link more

Comments

1

I'd also suggest that you probably want to stick to Python's conventions of using caps for classes (and no underscores) and snake case for everything else. This makes it easier for others to read your code and for you later when you go back and have to change things.

jayess gravatar image jayess  ( 2019-03-11 16:44:51 -0500 )edit

you are totally right - I passed the object and it actually worked like I expected. Also thanks for your suggestion - the conventions appear to be very helpful for a newbie like me :D.

KeyKeyQ gravatar image KeyKeyQ  ( 2019-03-12 04:42:42 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-03-10 13:25:47 -0500

Seen: 163 times

Last updated: Mar 11 '19