Guide on Using the Terminal Commands: ROSSERVICE

Modified on Tue, 17 Aug 2021 at 11:26 AM

This document focuses on using the terminal to launch the COBOTTA Driver and running the rosservice commands. There are three main sections to this document, the launching of the driver, the use of the rosservice commands in the terminal, and the python equivalent of each command (except for the CALSET). The rosservice commands section will not only display the code to enter into the terminal, but also the expected output from the terminal. If the user wants to interact with the COBOTTA in a different way, go back to the What's Next document. 


The following link provides information and the full code related to using all the rosservice commands: ROSSERVICE Commands 

 

 

 

 

Launching the COBOTTA Driver:


This section of the document will be used to launch the COBOTTA Driver.


Step 1:

Open a new terminal and enter the following to allow the driver to link to the source:
$ source ~/catkin_ws/devel/setup.bash


Note: 
If the catkin_ws folder is located in another directory, then the code above needs to be ran through that directory. Enter the following into the terminal before running the 'source' command line:


$ cd <directory>




Step 2:

Enter the following to launch the driver:


$ roslaunch denso_cobotta_driver 
denso_cobotta_driver.launch





Step 3:

Open a new terminal to run the 
rosservice commands since the window where the driver was launched will not allow for more commands to be entered. Enter the following into the new terminal so the rosservice commands will link to the source:


$ source ~/catkin_ws/devel/setup.bash





This concludes on launching the driver in the terminal. Proceed onto the ROSSERVICE Commands in Terminal section.


Finished

 

 

 

 

ROSSERVICE Commands in Terminal:


This section of the document will be used to launch the rosservice commands into the terminal and display what each command's expected output from the terminal should be.


Note: 
Some of the commands work in the terminal when launching the MOVEIT Software rather than launching the driver.



Motor Power Commands:

Get Motor Power Status:

Enter the following into the terminal to read the status of the Motor power:
$ rosservice call /cobotta/get_motor_state "{}"


Expected Output from Terminal When Motor Power is ON:

state: True
success: True


Expected Output from Terminal When Motor Power is OFF:

state: False
success: True


Set Motor Power ON/OFF:

Enter the following into the terminal to write the status of the Motor Power to ON or OFF:
Turn ON Motor Power:
$ rosservice call /cobotta/set_motor_state "state: true"


Expected Output from Terminal:
success: True



Turn OFF Motor Power:
$ rosservice call /cobotta/set_motor_state "state: false"


Expected Output from Terminal:
success: True




Brake Commands:

Get Brakes Status:

Enter the following into the terminal to read the status of the Brakes:
$ rosservice call /cobotta/get_brake_state "{}"

Expected Output from Terminal When Motor Power is ON:

state: [False, False, False, False, False, False]
success: True


Expected Output from Terminal When E-Stop is ON:

state: [True, True, True, True, True, True]
success: True


Expected Output from Terminal When Motor Power is OFF:

state: [False, False, False, False, False, False]
success: True


Set Brakes ON/OFF:

Enter the following into the terminal to write the status of the Brakes to ON or OFF:
Turn ON Brakes:
$ rosservice call /cobotta/set_brake_state 
"state: [true, true, true, true, true, true]"


Expected Output from Terminal When Motor Power is ON:
success: False


Expected Output from Terminal When Motor Power is OFF:
success: True



Turn OFF Brakes:
$ rosservice call /cobotta/set_brake_state 
"state: [false, false, false, false, false, false]"


Expected Output from Terminal When Motor Power is ON:
success: False


Expected Output from Terminal When Motor Power is OFF:
success: True




LED Command:

LED Manipulation:

Enter the following into the terminal to change the color and the blinking rate of the LED:
$ rosservice call /cobotta/set_LED_state 
"{red: 255, green: 255, blue: 255, blink_rate: 255}"

Expected Output from Terminal:

success: True


Note: 
The LED should turn white and blink at a slow rate. The following link contains different binary values to manipulate the LED on the COBOTTA: RGB Color Codes Chart 

Warning: 
When decreasing the blink_rate value (values closer to zero), the LED will begin to blink fast. Be cautious when decreasing the blink_rate since fast blinking lights can affect the body. 



Clearing Errors Commands:


Note: 
Turn OFF the Motor Power before executing the following commands. If motor is ON, a Bus Voltage Failure will occur. To clear this failure, use the 'Clearing Robot Errors' command.


Clearing Errors:

Enter the following into the terminal to clear all errors except for Fatal Errors:
$ rosservice call /cobotta/clear_error

Expected Output from Terminal:

success: True


Clearing Robot Errors:

Enter the following into the terminal to clear all Robot Errors:
$ rosservice call /cobotta/clear_robot_error

Expected Output from Terminal:

success: True


Clearing Safe State:

Enter the following into the terminal to clear the Safe State:
$ rosservice call /cobotta/clear_safe_state

Expected Output from Terminal:

Error: Service [/cobotta/clear_safe_state] is not available.


Note: 
The Safe State clearing will only report true if the Safe State needs to be cleared.




Executing a CALSET:


Note: 
Steps 1 to 8 will need to be executed only once to have the COBOTTA move to the CALSET position. Once the steps have been completed, the CALSET command can be used anytime.


Steps 1:

Steps 1 to 8 will demonstrate how to change the RANG Values for the COBOTTA to execute the CALSET. Start by scanning the QR code on the side of the COBOTTA to get the RANG values.
Step 2:

Go to the files explore application and enter the catkin_ws folder.
Step 3: 

Enter the src folder.
Step 4:

Enter the denso_cobotta_ros folder.
Step 5:

Enter the denso_cobotta_driver folder.
Step 6:

Enter the config folder.
Step 7:

Enter the parameters.yaml file.
Step 8:

Manually enter the RANG values by typing directly onto the file and changing the current values. Click Save to save the changes made and then exit out.
Execute the CALSET:

Enter the following into the terminal to execute the CALSET:
$ rosservice call /cobotta/exec_calset

Expected Output from Terminal:

success: True


Note: 
The following position is the "Home" position that DENSO Wave has designated for the COBOTTA: [0, 30, 100, 0, 50, 0] 


Warning: 
If the COBOTTA doesn't move to the "Home" Position after executing the CALSET, turn ON the Motor Power and try executing the CALSET command again.




This concludes the use of the rosservice commands in the terminal. Proceed to the ROSSERVICE Commands in Python section.



Finished

 

 

 

 

ROSSERVICE Commands in Python:


This section of the document will be used to explain and show the code used to execute the rosservice commands with python.



Libraries

Description:

The following libraries are used to communicate with the COBOTTA and to execute the rosservice commands

Code:

import os
import sys
import rospy
import rosservice
from denso_cobotta_driver.srv import GetMotorState, SetMotorState, GetBrakeState, SetBrakeState, SetLEDState, ClearError, ClearRobotError, ClearSafeState



Get Motor Status

Description:

The following function is used to obtain the status of the Motor Power. The try statement is used to try the following lines within the command. The rospy.wait_for_service line blocks the service call until it is available and contains a timeout of 3 seconds. The ServiceProxy command creates a reference to a ROS service for supported calls. The res = get_motor_state() and the return res.state are used to return the Motor Power status. The except statement is used after a try command to do all of the following except for when there is an error/failure. If the service call fails, the print statement will print "Service call failed" along with the error number. To see the full rosservice list, enter the following lines into the python file:

service_list = rosservice.get_service_list()
print(service_list)

Code:

def motor_power_status():
    rospy.wait_for_service('/cobotta/get_motor_state', 3.0)
    try:
        get_motor_state = rospy.ServiceProxy('/cobotta/get_motor_state', GetMotorState)
        res = get_motor_state()
        return res.state
    except rospy.ServiceException, e:
        print >> sys.stderr, " Service call failed: %s" % e



Set Motor Status

Description:

This following function uses user input to turn the Motor Power ON or OFF. When a user enters a '1', the Motor Power turns ON while entering a '0' turns the Motor Power OFF, and entering anything else will print an "Invalid input, please try again!" and return to the beginning of the function. Notice how the set_motor_state() contains Boolean Logic inside the parenthesis, this is due to the Motor Power command using Boolean Logic to communicate with the driver to allow the driver to understand that a True converts to a binary '1', thus knowing to turn on the motor. The print(res) is used to print the success of turning the Motor Power ON or OFF.

Code:

def motor_power_switch():
    rospy.wait_for_service('/cobotta/set_motor_state', 3.0)
    motorstate = int(input("Enter '1' for motor on or '0' for motor off: "))
    if motorstate == 1:
        set_motor_state = rospy.ServiceProxy('/cobotta/set_motor_state', SetMotorState)
        res = set_motor_state(True)
        print(res)
    elif motorstate == 0:
        set_motor_state = rospy.ServiceProxy('/cobotta/set_motor_state', SetMotorState)
        res = set_motor_state(False)
        print(res)
    else:
        print('Invalid input, please try again!')
        motor_power_switch()



Get Brakes Status

Description:

The following function is used to obtain the status of the brakes. The function works similar to the motor_power_status() function except that it uses get_brake_state() rather than get_motor_state().

Code:

def brakes_status():
    rospy.wait_for_service('/cobotta/get_motor_state', 3.0)
    try:
        get_brake_state = rospy.ServiceProxy('/cobotta/get_brake_state', GetBrakeState)
        res = get_brake_state()
        print(res)
        return res.state
    except rospy.ServiceException, e:
        print >> sys.stderr, " Service call failed: %s" % e 



Set Brakes Status

Description:

The following functions is used to set the status of the brakes to ON or OFF and only works when the Motor Power is OFF since it is a safety feature. This function utilizes user input to turn the brakes ON (entering a '1') or OFF (entering a '0'). Entering another input other '1' or '0' will print an "Invalid input, please try again!" statement and return to the beginning of the function. The set_brake_state() uses an array of Boolean Logic to set each of the 6 brakes ON or OFF.

Code:

def brakes_switch():
    rospy.wait_for_service('/cobotta/set_brake_state', 3.0)
    brakestate = int(input("Enter '1' for brakes to be on or '0' for brakes to be off: "))
    if brakestate == 1:
        set_brake_state = rospy.ServiceProxy('/cobotta/set_brake_state', SetBrakeState)
        res = set_brake_state([True, True, True, True, True, True])
        print(res)
    elif brakestate == 0:
        set_brake_state = rospy.ServiceProxy('/cobotta/set_brake_state', SetBrakeState)
        res = set_brake_state([False, False, False, False, False, False])
        print(res)
    else:
        print('Invalid input, pleas try again!')
        brake_switch()



Manipulate LED

Description:

The following function is used to manipulate the color and the blinking rate of the LED. This utilizes user input to determine the amount of red, green, blue to use ranging from 0 to 255 and the blinking rate from 0 to 255. If any of the inputs are over 255 or under 0, a print statement will print out "Invalid Number! I said 0 - 255, START OVER!" and will return the user to the beginning of the function. The set_LED_state() uses the values of 'reds', 'greens', 'blues', and 'blink_rates' as a list of decimal numbers to manipulate the LED.

Code:

def manipulate_LED():
    rospy.wait_for_service('/cobotta/set_LED_state', 3.0)
    reds = int(input("Enter the amount of Red to use from 0 - 255: "))
    if reds > 255:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    elif reds < 0:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    else:
        print('Good Choice!')
    greens = int(input("Enter the amount of Green to use from 0 - 255: "))
    if greens > 255:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    elif greens < 0:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    else:
        print('Good Choice!')
    blues = int(input("Enter the amount of Blue to use from 0 - 255: "))
    if blues > 255:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    elif blues < 0:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    else:
        print('Good Choice!')
    blink_rates = int(input("Enter the amount of how fast to blink from 0 - 255: "))
    if blink_rates > 255:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    elif blink_rates < 0:
        print("Invalid Number! I said 0 - 255, START OVER!")
        manipulate_LED()
    else:
        print('Good Choice!')
    set_LED_state = rospy.ServiceProxy('/cobotta/set_LED_state', SetLEDState)
    res = set_LED_state(reds, greens, blues, blink_rates)
    print(res)



Clearing Errors:

Description:

The following function clears 3 types of errors: clearing all errors except for fatal ones, clearing robot errors, and clearing the safe state. Before running the function, turn OFF the Motor Power to avoid a Bus Voltage Failure. This function first checks if the user would like to clear an error or not, if '1' is entered, the function enters to another user input to see what clearing error the user would like to choose. The print(res) statement prints the success of the clearing of the error. The clear_safe_state() works only if there needs to be a clearing of the safe state, if the safe state is working, then it will print that it is unavailable just as if it was entered using the rosservice command in the terminal (refer to the Guide on Using the Terminal Commands: ROSSERVICE document).

Code:

def error_clearer():
    rospy.wait_for_service('/cobotta/clear_error', 3.0)
    rospy.wait_for_service('/cobotta/clear_robot_error', 3.0)
    rospy.wait_for_service('/cobotta/clear_safe_state', 3.0)
    check = int(input("Would you like to clear an error?\nEnter '1' for Yes or '0' for No: "))
    if check == 0:
        print('No errors here, moving on!')
    elif check == 1:
        error = int(input("What clearing error option do you want to use?\nEnter '1' for clear error, '2' for clear robot error, '3' for clear safe state: "))
        if error == 1:
            clear_error = rospy.ServiceProxy('/cobotta/clear_error', ClearError)
            res = clear_error()
            print(res)
        elif error == 2:
            clear_robot_error = rospy.ServiceProxy('/cobotta/clear_robot_error', ClearRobotError)
            res = clear_robot_error()
            print(res)
        elif error == 3:
            clear_safe_state = rospy.ServiceProxy('/cobotta/clear_safe_error', ClearSafeState)
            res = clear_safe_state()
            print(res)
        else:
            print("Invalid input! Try Again!")
            error_clearer()
    else:
        print("Invalid input! Try again!")
        error_clearer()



Info:
FINISHED.
This concludes the use of the commands for interacting with the COBOTTA. Go back to the What's Next document to see other options for interacting with the COBOTTA.




Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article