Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

[store points] evaluate format #23

Closed
jschleicher opened this issue Nov 25, 2019 · 4 comments
Closed

[store points] evaluate format #23

jschleicher opened this issue Nov 25, 2019 · 4 comments
Assignees

Comments

@jschleicher
Copy link
Contributor

for easy storage

  • humand-readable / edit(?)
  • easy to import into python-(API)-script
  • allows names and cartesian / joint positions
@Hardthof Hardthof self-assigned this Dec 2, 2019
@Hardthof
Copy link
Contributor

Hardthof commented Dec 2, 2019

  • plain text - python dict
    • message_converter can serialize a ROS message object into a dict and vice versa
    • pprint.pformat() formats the dict with line-breaks and indentation
    • eval() or ast.literal_eval() can read the dict back and message_converter makes a ROS type from it
  • rosbag (ROS-native)
    • abuse topic names as position names
    • unnecessary timestamp
    • intrinsic ROS message representation
  • json (different format than ROS that typically uses yaml)
  • pickle converts objects into a binary format (non-human-readable)

@Hardthof
Copy link
Contributor

Hardthof commented Dec 2, 2019

Open Questions:

  • Consistency with robot_model? E.g. loading a different gripper / tool, (major) changes in workspace
  • how to handle consistency when editing files manually (joints vs. pose)

@jschleicher
Copy link
Contributor Author

jschleicher commented Dec 3, 2019

To store direct python structures like this

position_start = Pose()

position_start.position.x = 0.73
position_start.position.y = -0.2
position_start.position.z  = 0.3

would give additional advantages:

  • easy calculations (but lost on overwriting) position_machine.z = position_start.z + 0.3
  • direct import positions as p without additional loader module
  • syntax completion would know, which variable names exist
  • intrinsic semantics (type-knowledge together with values)

Should we extend rospy_message_converter to allow such output?
Quick try didn't find a straight-forward way: Print a string representation with native rospy message overloads of repr() isn't parsable using eval() afterwards...

@DamKoVosh
Copy link
Collaborator

We could do something along those lines:

import inspect
import genpy

def recreate_rep(msg):
   if not isinstance(msg, genpy.Message):
      return str(msg)

   arguments = {}
   for a in dir(msg):
      if not (a.startswith("_") or "serialize" in a) and not callable(getattr(msg, a)):
         arguments[a] = recreate_rep(getattr(msg, a))
   
   args_string = ', '.join('{}={}'.format(key, value) for key, value in arguments.items())
   repr_string = "%s(%s)" % (msg.__class__.__name__ , args_string)
   return repr_string

so this

from geometry_msgs.msg import Pose, Point
recreate_rep(Pose(position=Point(x=2, z=3)))

results in

'Pose(position=Point(y=0.0, x=2, z=3), orientation=Quaternion(y=0.0, x=0.0, z=0.0, w=0.0))'

and eval works again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants