PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label ros. Show all posts
Showing posts with label ros. Show all posts

Monday, July 11, 2022

[FIXED] How to get ROS MSG length in python?

 July 11, 2022     message, python, ros     No comments   

Issue

I have a problem that needs to count the length of each ROS topic msg.

I modified rostopic(/opt/ros/smart-ros/lib/python2.7/dist-packages/rostopic / __ init__.py):

Class CallbackEcho(object) ->
Def callback (self, data, callback_args, current_time = None):
    Print('message length =',sys.getsizeof(data)) #statics msg length

But when the message contains a vector or struct list, the length is incorrect.

Please help solve this problem?

Thanks.


Solution

The problem is the behaviour of sys.getsizeof:

Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to.

This means only the size of the reference to a list is used to calculate the object size.

There are already a few questions dealing with this:

  • How do I determine the size of an object in Python?
  • In-memory size of a Python structure

The solution is to use Pympler and its module asizeof which provides a function to the required calculation:

Function asizeof calculates the combined (approximate) size of one or several Python objects in bytes

After installing the package using pip

pip install pympler

and importing it to your code like

from pympler.asizeof import asizeof

you are able to print the correct object size in your callback like

print('Size: ' + str(asizeof(data)))


Answered By - Fruchtzwerg
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, June 29, 2022

[FIXED] How to make comments multiple lines and one line in .wbt files used as world files in WeBots

 June 29, 2022     comments, ros, webots     No comments   

Issue

In WeBots and using programs with ROS2 you need to use world files with the .wbt extensions.

Does someone know how to comment one line or multiple lines ?

Thanks.


Solution

Yes, you can use the # character in front of a line to comment it, like in Python.



Answered By - Olivier Michel
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing