Here are some resources that might help you figure it out on your own.
Hint: Try checking the types of your variables to see if there is a deference between
If you are still stuck, see below for the solution
The issue is on line 21 when you call
request is the variable that represents message received by your Subscriber. It is of type
String as defined in std_msgs.msg (which you imported). To work with the String message effectively, you need to understand how it is structured. In a terminal, run the following
rosmsg show String
This shows the contents of the message type
The first line indicates what package it is from (std_msgs). The second line shows the type variable name of the message’s fields. In this case there is a single field of type
string named data.
To access a field from a message, use the following syntax:
string is a build in type in Python. On the other hand,
String is a message that has a member
data of type
You can remove the (syntax) error by changing line 21 to:
requestfloat = float(request.data)
As a final note: Everything I have detailed is specific to how messages are structured for Publishers and Subscribers. I suspect that you are intending to use a Service instead. I encourage you to review the sections on ROS Service Servers and Clients, paying special attention to how thy differ form Publishers and Subscribers.