Skip to content

Commit

Permalink
Update module names in Python examples
Browse files Browse the repository at this point in the history
Signed-off-by: Rhys Mainwaring <[email protected]>
  • Loading branch information
srmainwaring committed Apr 30, 2024
1 parent 499674f commit f564b68
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 27 deletions.
2 changes: 1 addition & 1 deletion python/gz_service_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import argparse

from gz.transport import Node
from gz.python.transport import Node

def main():
# process command line
Expand Down
2 changes: 1 addition & 1 deletion python/gz_service_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$ gz service -l
'''

from gz.transport import Node
from gz.python.transport import Node

def main():
# create a transport node
Expand Down
14 changes: 12 additions & 2 deletions python/gz_topic_echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@
'''

import argparse
import os
import time

from gz.transport import SubscribeOptions
from gz.transport import Node
# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.python.transport import SubscribeOptions
from gz.python.transport import Node


# callback - prints the raw message
def cb(msg):
Expand Down
3 changes: 2 additions & 1 deletion python/gz_topic_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

import argparse

from gz.transport import Node
from gz.python.transport import Node


def main():
# process command line
Expand Down
2 changes: 1 addition & 1 deletion python/gz_topic_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
$ gz topic -l
'''
from gz.python.transport import Node

from gz.transport import Node

def main():
# create a transport node
Expand Down
25 changes: 17 additions & 8 deletions python/import_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import time
import os

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.any_pb2 import Any
from gz.msgs.header_pb2 import Header
from gz.msgs.stringmsg_pb2 import StringMsg
from gz.msgs.time_pb2 import Time

from gz.msgs.extras import make_time
from gz.msgs.extras import take_time
from gz.msgs.extras import take_topic_info
from gz.msgs.extras import take_wrench
from gz.python.msgs_extras import make_time
from gz.python.msgs_extras import take_time
from gz.python.msgs_extras import take_topic_info
from gz.python.msgs_extras import take_wrench

from gz.transport import AdvertiseMessageOptions
from gz.transport import Node
from gz.python.transport import AdvertiseMessageOptions
from gz.python.transport import Node


def main():
Expand All @@ -39,9 +46,11 @@ def main():
msg = Any()
msg = Header()
msg = StringMsg()
msg = Time()

# msgs functions
msg = make_time()
take_time(msg)

# transport types
opts = AdvertiseMessageOptions()
Expand Down
10 changes: 10 additions & 0 deletions python/msgs_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.header_pb2 import Header
from gz.msgs.double_pb2 import Double
from gz.msgs.double_v_pb2 import Double_V
Expand Down
14 changes: 12 additions & 2 deletions python/pub_all_msg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import time

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.cmd_vel2d_pb2 import CmdVel2D
from gz.msgs.double_pb2 import Double
from gz.msgs.double_v_pb2 import Double_V
Expand All @@ -35,8 +44,9 @@
from gz.msgs.vector3d_pb2 import Vector3d
from gz.msgs.wrench_pb2 import Wrench

from gz.transport import AdvertiseMessageOptions
from gz.transport import Node
from gz.python.transport import AdvertiseMessageOptions
from gz.python.transport import Node


def main():
# Create a transport node and advertise options
Expand Down
13 changes: 11 additions & 2 deletions python/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import time

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.stringmsg_pb2 import StringMsg

from gz.transport import AdvertiseMessageOptions
from gz.transport import Node
from gz.python.transport import AdvertiseMessageOptions
from gz.python.transport import Node

def main():
# Create a transport node and advertise a topic
Expand Down
13 changes: 11 additions & 2 deletions python/rover_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@

from scipy.spatial.transform import Rotation as Rotation
import math
import os
import time

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.header_pb2 import Header
from gz.msgs.pose_pb2 import Pose
from gz.msgs.quaternion_pb2 import Quaternion
from gz.msgs.time_pb2 import Time
from gz.msgs.twist_pb2 import Twist
from gz.msgs.vector3d_pb2 import Vector3d

from gz.transport import AdvertiseMessageOptions
from gz.transport import Node
from gz.python.transport import AdvertiseMessageOptions
from gz.python.transport import Node

def main():
# Create a transport node and advertise a topic
Expand Down
13 changes: 11 additions & 2 deletions python/rover_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@
# limitations under the License.

import time
import os
import typing

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.pose_pb2 import Pose
from gz.msgs.quaternion_pb2 import Quaternion
from gz.msgs.twist_pb2 import Twist
from gz.msgs.vector3d_pb2 import Vector3d

from gz.transport import Node
from gz.transport import SubscribeOptions
from gz.python.transport import Node
from gz.python.transport import SubscribeOptions


def pose_cb(msg: Pose) -> None:
Expand Down
13 changes: 11 additions & 2 deletions python/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
# limitations under the License.

import time
import os
import typing

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.stringmsg_pb2 import StringMsg

from gz.transport import SubscribeOptions
from gz.transport import Node
from gz.python.transport import SubscribeOptions
from gz.python.transport import Node

def cb(msg: StringMsg) -> None:
print("Msg: [{}] from Python".format(msg.data))
Expand Down
16 changes: 13 additions & 3 deletions python/transport_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os

# alias gz.msgs{GZ_MSGS_VER} to gz.msgs
if os.environ["GZ_VERSION"] == "garden":
from gz import msgs9 as msgs
elif os.environ["GZ_VERSION"] == "harmonic":
from gz import msgs10 as msgs
else:
raise Exception(f"Invalid GZ_VERSION: {os.environ['GZ_VERSION']}")

from gz.msgs.header_pb2 import Header
from gz.msgs.time_pb2 import Time
from gz.msgs.quaternion_pb2 import Quaternion
Expand All @@ -22,9 +32,9 @@
from gz.msgs.vector3d_pb2 import Vector3d
from gz.msgs.wrench_pb2 import Wrench

from gz.transport import AdvertiseMessageOptions
from gz.transport import SubscribeOptions
from gz.transport import Node
from gz.python.transport import AdvertiseMessageOptions
from gz.python.transport import SubscribeOptions
from gz.python.transport import Node

from google.protobuf.internal import api_implementation

Expand Down

0 comments on commit f564b68

Please sign in to comment.