TAURD
September 8, 2022, 1:45pm
1
Hello,
I have the display of the direction
self.get_logger().info('direction is '+ str(request.direction))
I’m trying to display the angular_velocity
I thought abut something like this:
self.get_logger().info('time is %d' %(request.time))
I have tried some other syntax (with int
, with +request.time+
etc)
Well, it doesn’t work
Any ideas?
Thank you
Hello @TAURD ,
Try converting it into a string with str(request.time)
Since we are using Python 3. I am a big fan of the newest string formatting, called f-strings . You just add f before the ‘…’ and directly type the variables’ name between {} wherever in the string you want. For sure an example is much simpler to understand than my explanation.
>>> recommended_sleep_hours = 8
>>> f'The recommended sleeping hours for an average adult are {recommended_sleep_hours}. Rest is essential!'
'The recommended sleeping hours for an average adult are 8. Rest is essential!'
If you ever forget about f-string formatting, just go to your search bar and ask for fstring.help
1 Like
TAURD
September 9, 2022, 11:47am
4
albertoezquerro:
str(request.time)
Hello
I’ve tried it with this code
self.get_logger().info('time is ' + str(request.time))
process has died
It killed the server (launch file) in shell #1
Sorry for that.
Do you have any other ideas?
Thank you
TAURD
September 9, 2022, 11:51am
5
GasPatxo:
f
I’ve tried it with this code
self.get_logger().info(f'time is {request.time}')
process has died
It killed the server (launch file) in shell #1
Sorry for that.
Do you have any other ideas?
Thank you
Then it is most likely not a sting formatting issue, we have to dig deeper.
Does it simply stop, or does it report back something? If so, could you share what it prints?
Can you also share your code please?
TAURD
September 9, 2022, 1:03pm
7
Hello,
How can I share the files in this forum?
So for my robot spins left or right with the angular velocity given
e.g.
for
ros2 launch services_quiz services_quiz_server.launch.py
in shell #1 and for
ros2 run services_quiz services_quiz_client right 10.0 1
the robot turn right with 10.0 rad/sec.
I still need to input the third variable for time cause my function expect it but it does nothing.
I still need to crack the time issue.
Thank you
TAURD
September 9, 2022, 1:31pm
8
Hello
In a different QU of mine you replied with
That is something I could not find much information about. So it is very unclear to me what is the proper way of doing this. I researched into rclpys’ documentation about the timer object and I ended up doing the following:
def turn_callback(self, request, response):
self.get_logger().info(
f"I've been called for {request.time}s at {request.angular_velocity}rad/sec towards the {request.direction}")
self.cmd.angular.z = request.angular_velocity if request.directi…
I give partial quote here
( f"I've been called for {request.time}s...
see the "
sign
in a previous answer of yours in this thread you wrote with '
sign
see picture below
What say you, what is the proper form?
I would try it myself but for some time noe the shell is not available
Thank you
In python both ’ and " quotation marks (QM) can be used to represent a string, it makes no difference. I personally prefer using the singe QM, but again, it makes no difference. In that partial quote you mention I used double QM because I wanted to use the single QM in the sentence. See it underscored below
“I ’ ve been called for {re…”
You can find great resources online on python strings .
PS: Have you tried killing the shell pressing on the ? It will automatically restart a fresh new one.
TAURD
September 9, 2022, 1:54pm
10
Of course
and I gave it few more minutes but now it is not better
No IDE
No Notebook
TheConstruct, please advise if you see this msg.
TAURD
September 11, 2022, 9:55am
11
Hello
This is the solution (originally from GasPatxo ) here
self.get_logger().info(f"I will spin {request.direction} around Z axis for {request.time}[sec] at {request.angular_velocity}[rad/sec]")
Just copied the entire code line and changed the text.
1 Like