move-object-example.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # ---------------------------------------------------------------------
4 # This example shows how to:
5 # - Call a MVSIM service.
6 # - Use it to move an object in an arbitrary way.
7 #
8 # Install python3-mvsim, or test with a local build with:
9 # export PYTHONPATH=$HOME/code/mvsim/build/:$PYTHONPATH
10 # ---------------------------------------------------------------------
11 
12 from mvsim_comms import pymvsim_comms
13 from mvsim_msgs import SrvSetPose_pb2
14 import time
15 import math
16 
17 
18 def setObjectPose(client, objectName, x, y, theta_rad):
19  # Send a set pose request:
20  req = SrvSetPose_pb2.SrvSetPose()
21  req.objectId = objectName # vehicle/robot/object name in MVSIM
22  req.pose.x = x
23  req.pose.y = y
24  req.pose.z = 0
25  req.pose.yaw = theta_rad
26  req.pose.pitch = 0
27  req.pose.roll = 0 # math.radians(0.0)
28  # ret =
29  client.callService('set_pose', req.SerializeToString())
30 
31 
32 if __name__ == "__main__":
33  client = pymvsim_comms.mvsim.Client()
34  client.setName("tutorial1")
35  print("Connecting to server...")
36  client.connect()
37  print("Connected successfully.")
38 
39  for i in range(1000):
40  th = i*0.02
41  R = 5
42  setObjectPose(client, 'r1', math.sin(th)*R, R*(1-math.cos(th)), th)
43  time.sleep(0.01)
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
def setObjectPose(client, objectName, x, y, theta_rad)


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21