ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

When you are calling your methods say, this one:

def placed_obj(req):
    if req.transition == 1:
        currentstatus = "at-loc-1"
    elif req.transition == 0:
        currentstatus = "START"
    else:
        rospy.loginfo("Invalid command")
    exit

You are actually creating a new variable called 'currentstatus' within that method and that only lasts for the life of that method. Try extending the scope of the variable by using the global keyword. Like this:

def placed_obj(req):
    global current_status
    if req.transition == 1:
        currentstatus = "at-loc-1"
    elif req.transition == 0:
        currentstatus = "START"
    else:
        rospy.loginfo("Invalid command")
    exit

Doing this will allow you to modify a variable outside of the current scope.
You will need to do this in all the methods where you attempt to modify 'currentstatus'

When you are calling your methods say, this one:

def placed_obj(req):
    if req.transition == 1:
        currentstatus = "at-loc-1"
    elif req.transition == 0:
        currentstatus = "START"
    else:
        rospy.loginfo("Invalid command")
    exit

You are actually creating a new variable called 'currentstatus' within that method and that only lasts for the life of that method. Try extending the scope of the external variable 'currentstatus' by using the global keyword. Like this:

def placed_obj(req):
    global current_status
    if req.transition == 1:
        currentstatus = "at-loc-1"
    elif req.transition == 0:
        currentstatus = "START"
    else:
        rospy.loginfo("Invalid command")
    exit

Doing this will allow you to modify a variable outside of the current scope.
You will need to do this in all the methods where you attempt to modify 'currentstatus'

When you are calling your methods say, this one:

def placed_obj(req):
    if req.transition == 1:
        currentstatus = "at-loc-1"
    elif req.transition == 0:
        currentstatus = "START"
    else:
        rospy.loginfo("Invalid command")
    exit

You are actually creating a new variable called 'currentstatus' within that method and that only lasts for the life of that method. Try extending the scope of the external variable 'currentstatus' by using the global keyword. Like this:

def placed_obj(req):
    global current_status
    if req.transition == 1:
        currentstatus = "at-loc-1"
    elif req.transition == 0:
        currentstatus = "START"
    else:
        rospy.loginfo("Invalid command")
    exit

Doing this will allow you to modify a variable outside of the current scope.
You will need to do this in all the methods where you attempt to modify 'currentstatus'

There are other issues in your code such as the 'exit' oddity but your core question, I believe will be resolved by the use of the global keyword.