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

Qwertazertyl's profile - activity

2020-12-18 13:24:04 -0500 marked best answer Rosservice Kinetic vs Melodic

I'm currently working on a project that was left partly complete by someone else, a while ago. The project is written with ROS Kinetic, but I'd like to make it compatible with melodic too (running on ubuntu 16.04 and 18.04 respectively, both on VMs). I've had some issues, though. Rosservice commands in particular don't work with Melodic, while they do work with Kinetic. I get errors saying "String has no len()" (this is a std_msgs String) but I never called len() in my code! Are there any differences between the implementation of Rosservice that I should be aware of? Sorry if it's something simple; I'm completely new to ROS.

The code:

import rospy
import ethernetcommunicator
import serialcommunicator
from std_msgs.msg import Bool
from std_msgs.msg import Float64
from std_msgs.msg import String
from mswrapper.srv import *

cm = serialcommunicator.Serialcommunicator()

def send_command_callback(data):
    return cm.send_command(data.data)

def set_speed_callback(data):
    cm.motor_jog(data.data)

def handle_send_command(req):
    controller_response = cm.send_command(str(req.command)[6:])
    if not controller_response:
        controller_response = ""
    return SendCommandResponse(String(controller_response))

def loop():
    input_1_pub = rospy.Publisher('mswrapper/input_1', Bool, queue_size=10)
    rospy.Subscriber('mswrapper/set_speed', Float64, set_speed_callback)
    rospy.Subscriber('mswrapper/send_command', String, send_command_callback)
    rospy.init_node('asciicom', anonymous=False)
    send_command_service = rospy.Service('mswrapper/send_command', SendCommand, handle_send_command)
    rate = rospy.Rate(1)
    while not rospy.is_shutdown():
        input_1_pub.publish(cm.get_input_1())
        rate.sleep()

if __name__ == '__main__':
    try:
        loop()
    except rospy.ROSInterruptException:
        pass

The error message is quite odd:

ERROR: Unable to send request. One of the fields has an incorrect type: 

     <type 'exceptions.TypeError'>: 'object of type 'String' has no len()' when writing 'data: 'mtr on''

srv file:

std_msgs/String command
    string data
---
std_msgs/String result
    string data

As you can see, there is no line number provided, only an error and a printout of my .srv file.

Meanwhile, on the node I'm running this from, I get another error message:

[ERROR] [numbers]: incoming connection failed: unable to receive data from sender, check sender's logs for details

So I have no idea where the error is coming from since I don't get a line number or even a file where this is taking place. Any help would be much appreciated!

2019-07-05 21:45:42 -0500 received badge  Famous Question (source)
2019-07-03 18:59:38 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 18:59:06 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 18:58:49 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 18:36:46 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 18:36:12 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 18:33:26 -0500 commented question Rosservice Kinetic vs Melodic

That's the full error. I'll update the whole program if you want.

2019-07-03 18:33:19 -0500 commented question Rosservice Kinetic vs Melodic

That's the full error code. I'll update the whole program if you want.

2019-07-03 18:05:46 -0500 commented question Rosservice Kinetic vs Melodic

The error numbers change every time...

2019-07-03 12:41:43 -0500 commented answer Rosservice Kinetic vs Melodic

And should I just move the service definition out of loop? Or should I put it in main, another function, etc?

2019-07-03 12:40:26 -0500 commented answer Rosservice Kinetic vs Melodic

I tried changing to req.command.data but still get the same "String has no len()" error. Also, I tried adding some print

2019-07-03 12:22:03 -0500 received badge  Notable Question (source)
2019-07-03 11:48:15 -0500 commented question Rosservice Kinetic vs Melodic

Code has been added

2019-07-03 11:47:27 -0500 commented answer Rosservice Kinetic vs Melodic

The thing is, I didn't call len() anywhere in my code, and I don't have a line number to work with. That's why I thought

2019-07-03 11:46:27 -0500 commented answer Rosservice Kinetic vs Melodic

The thing is, I didn't call len() anywhere in my code, and I don't have a line number to work with.

2019-07-03 11:45:31 -0500 commented answer Rosservice Kinetic vs Melodic

The thing is, I didn't call len() anywhere in my code, and I don't have a line number to work with.

2019-07-03 11:41:18 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 11:40:31 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 11:39:02 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 11:38:45 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 11:31:45 -0500 received badge  Supporter (source)
2019-07-03 11:25:02 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 09:03:34 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-03 09:03:34 -0500 received badge  Editor (source)
2019-07-03 03:26:18 -0500 received badge  Popular Question (source)
2019-07-02 20:55:35 -0500 commented question Rosservice Kinetic vs Melodic

Edited, is this ok?

2019-07-02 20:55:06 -0500 edited question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while

2019-07-02 20:23:43 -0500 asked a question Rosservice Kinetic vs Melodic

Rosservice Kinetic vs Melodic I'm currently working on a project that was left partly complete by someone else, a while