Ask Your Question
0

Service Server and Client not working when launch by launch file

asked 2020-01-12 15:31:13 -0500

mhyde64 gravatar image

Hello all.

I am using a pandas data frame to format instructions and the data frame is hosted in a service server. I then have a client that is imported into a position supervising node. The client is a member of the position supervisor class which obviously will pull then next instruction on command.

If I run the parameter setup scripts and then rosrun each of these nodes then everything works as expected. However, I built a launch file and now every time the client is triggered to pull an instruction I get an error saying that the client is receiving a null response from the server.

Error:

[ERROR] [1578864176.167369]: Error processing request: local variable 'resp' referenced before assignment
['Traceback (most recent call last):\n', '  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 629, in _handle_request\n    response = convert_return_to_response(self.handler(request), self.response_class)\n', '  File "/home/mhyde/arm_cws/src/arm_data_frame/src/nodes/dataFrameServer.py", line 66, in handleRequest\n    return resp\n', "UnboundLocalError: local variable 'resp' referenced before assignment\n"]
[ERROR] [1578864176.177881]: bad callback: <bound method positionSupervisor.arduinoStateCallback of <__main__.positionSupervisor object at 0x7fbb19878650>>
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "/home/mhyde/arm_cws/src/position_supervisor/src/nodes/positionSupervisor.py", line 99, in arduinoStateCallback
    self.pullInstruction()
  File "/home/mhyde/arm_cws/src/position_supervisor/src/nodes/positionSupervisor.py", line 52, in pullInstruction
    self.instruction = self.instructionClient.client()
  File "/home/mhyde/arm_cws/src/arm_data_frame/src/arm_data_frame/dataFrameClient.py", line 52, in client
    return coor.motionType, coor.xCoor, coor.yCoor, coor.zCoor, coor.velFac, coor.accFac
AttributeError: 'NoneType' object has no attribute 'motionType'

Again, if I rosrun the dataFrameServer and the positionSupervisor and then manually publish to /arduinoState then everything works perfectly. I only get this error if I launch the dataFrame and Supervisor in a launch file.

Launch File:

<launch>
    <node name="dataFrameServer" pkg="arm_data_frame" type="dataFrameServer.py" />
    <node name="positionSupervisorParams" pkg="position_supervisor" type="positionSupervisorParams.py" />
    <node name="positionSupervisor" pkg="position_supervisor" type="positionSupervisor.py" />
</launch>

I did try removing nodes from the launch file and it appears the issue is coming from including the position supervisor in the launch file. When I remove it, run the launch file, and then rosrun the positionSupervisor then everything works well.

Below is the code for everything involved. I don't think the param files are casuing the issues.

Server:

#!/home/mhyde/vEnvs/rosPy/bin/python

'''
ROS Service - Server:

Feeds Coors from the CSV File to
the Data Handler upon service request.

Implements a Pandas DataFrame to contain
Coor information as well as actuator
and motion commands.
'''

import rospy
from arm_msgs.srv import instructionPass, \
    instructionPassResponse
from pandas import DataFrame, read_csv


class server(object):
    '''
    Coor Distributor

    topic =  /instructionPass
    node  =  /instructionPassServer
    '''

    def __init__(self, filePath):
        self.roboRoutine = DataFrame(read_csv(filePath, sep=","))
        self.index = 0
        self.instructionCount = 0

    def countInstructions(self):
        '''
        Counts the amount of Coors
        in routine
        '''
        self.instructionCount = self.roboRoutine ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-01-13 17:26:29 -0500

mhyde64 gravatar image

The problem was in :

def client(self):
        '''
        Client Implementation
        '''
        req = False
        if len(sys.argv) == 1:
            req = True
        else:
            print self.usage()
        print "Requesting Coordinate ... "
        coor = self.requestCoordinate(req)
        return coor.motionType, coor.xCoor, coor.yCoor, coor.zCoor, coor.velFac, coor.accFac

Apparently len(sys.argv) did not equal 1. I should have realized the error message I was receiving was the one that was included in the code. That's what I get for not fully understanding code before I use it.

edit flag offensive delete link more

Comments

1

I've marked your answer to be the accepted answer, as it would seem to be the actual cause of the problem you reported.

gvdhoorn gravatar image gvdhoorn  ( 2020-01-14 05:15:06 -0500 )edit
1

answered 2020-01-12 16:10:56 -0500

gvdhoorn gravatar image

updated 2020-01-12 16:23:42 -0500

We see this in your "Server" script:

if __name__ == '__main__':
    try:
        [..]
        serv = server(
            "~/arm_cws/src/arm_data_frame/data/testCoordinates.csv")
        [..]

you are using a relative path for filePath.

roslaunch changes the CWD for all nodes before starting them. See #q235337 for a previous Q&A about this, and the links to the roslaunch documentation where this is explained.

So this will work with rosrun, but not with roslaunch.

If you want to know more about it, please search ROS Answers with Google (append site:answers.ros.org to your query).

To make things work: use absolute paths, and to avoid hard-coding an absolute path into your scripts, use the $(find <your_pkg_name>) substitution arg supported by roslaunch. That would allow you to use package relative paths.

But you of course don't have to use that. As long as the parameter contains an absolute path, it should work.

edit flag offensive delete link more

Comments

1

You might actually want to add some checking and error handling if the .csv cannot be found / opened. Right now the code only deals with the "happy path".

gvdhoorn gravatar image gvdhoorn  ( 2020-01-12 16:16:10 -0500 )edit

That is a good point. I have a few exceptions that I need to work into this program still.

Let me play around with your solution (I have a bit of reading to do) and I'll be sure to come back and verify it.

Thanks so much !

mhyde64 gravatar image mhyde64  ( 2020-01-12 19:43:43 -0500 )edit

Actually, here's something I realized.

The error persists regardless of if I open the dataFrame with a launch file or rosrun. The error only occurs when I include the positionSupervisor in the launch file. This node does not care about the filepath nor does the filepath care about this node.

I was able to include <param name="filePath" value="$(find arm_data_frame)/testCoordinates.csv/> to my launch file and the nodes still work with rosrun but it did not fix my issue with launching. Again, the issue only happens if positionSupervisor (which contains the client) is included in the launch file.

Any other ideas?

The whole project is public on GitHub if you want to check it out there: https://github.com/HydeMikhail/Friday...

mhyde64 gravatar image mhyde64  ( 2020-01-12 20:05:45 -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

1 follower

Stats

Asked: 2020-01-12 15:31:13 -0500

Seen: 82 times

Last updated: Jan 13