├── .gitignore
├── Lab2_Environment.ttt
├── Lab2_Environment_NoDoors.ttt
├── PythonWorkspace
├── binary_grid.npy
├── go.sh
├── idash.py
├── simpleTest.py
├── ringbuffer.py
├── datastructs.py
├── Lab2Program.py
├── vrepConst.py
└── vrep.py
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | *.so
2 | *.pyc
3 |
--------------------------------------------------------------------------------
/Lab2_Environment.ttt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youralien/vrep-maze-solver/HEAD/Lab2_Environment.ttt
--------------------------------------------------------------------------------
/Lab2_Environment_NoDoors.ttt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youralien/vrep-maze-solver/HEAD/Lab2_Environment_NoDoors.ttt
--------------------------------------------------------------------------------
/PythonWorkspace/binary_grid.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/youralien/vrep-maze-solver/HEAD/PythonWorkspace/binary_grid.npy
--------------------------------------------------------------------------------
/PythonWorkspace/go.sh:
--------------------------------------------------------------------------------
1 | # start vrep
2 | # timerunmsecs=$(expr 1000 \* 120)
3 | # bash ~/apps/V-REP_PRO_EDU_V3_2_3_rev4_64_Linux/vrep.sh ~/Documents/studyaway/DistAutoRobo/LAB2/A0149643X_LAB2/Lab2_Environment_NoDoors.ttt -s$timerunmsecs -gREMOTEAPISERVERSERVICE_19999_FALSE_FALSE &
4 |
5 | python Lab2Program.py &
6 | bash ~/apps/V-REP_PRO_EDU_V3_2_3_rev4_64_Linux/vrep.sh ~/Documents/studyaway/DistAutoRobo/LAB2/A0149643X_LAB2/Lab2_Environment_NoDoors.ttt -gREMOTEAPISERVERSERVICE_19999_FALSE_FALSE
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vrep-maze-solver
2 | the ePuck robot (2 wheel differential drive) plans a path and tries to avoid obstacles. Implemented in the VREP simulator environment. Inspired by NUS EE4306 - Distributed Autonomous Robotic Systems Lab 2.
3 |
4 | # How to Run
5 | First, enter the `PythonWorkspace` directory
6 | ```
7 | cd PythonWorkspace/
8 | ```
9 | Then open VREP with a continous remote API going on port 19999. On linux, it looks like
10 | ```
11 | bash /absolute/path/to/vrep.sh /absolute/path/to/Lab2_Environment.ttt -gREMOTEAPISERVERSERVICE_19999_FALSE_FALSE
12 | ```
13 | Finally, start the python program
14 | ```
15 | python Lab2Program.py
16 | ```
17 |
18 |
--------------------------------------------------------------------------------
/PythonWorkspace/idash.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plt
2 |
3 | # interactive plotting
4 | plt.ion()
5 |
6 | class IDash(object):
7 |
8 | grid_shapes = [
9 | (1,1)
10 | , (2,1)
11 | , (3,1)
12 | , (2,2)
13 | , (3,2)
14 | , (3,2)
15 | , (2,4)
16 | , (2,4)
17 | ]
18 |
19 | def __init__(self, framerate=0.05):
20 | """
21 | Parameters
22 | ----------
23 | framerate: num, in seconds
24 | """
25 | self.framerate = framerate
26 | self.funcs = []
27 | self.n_axes_handled = False
28 |
29 | def handle_n_axes(self):
30 | n_axes = len(self.funcs)
31 | if n_axes > len(self.grid_shapes):
32 | print "idash doesn't support that many."
33 |
34 | self.rows, self.cols = self.grid_shapes[n_axes-1] # 0 versus 1 indexing
35 | figscale = 4
36 | figsize = (self.cols * figscale, self.rows * figscale)
37 | plt.figure(figsize=figsize)
38 | self.n_axes_handled = True
39 |
40 | def add(self, func):
41 | """ func is a plotting function handle, where func does not expect args """
42 | self.funcs.append(func)
43 |
44 | def plotframe(self):
45 | """ plot a single frame. For interactive plotting, we usually plot frames to create a "movie" """
46 | if not self.n_axes_handled:
47 | self.handle_n_axes()
48 |
49 | for count, func in enumerate(self.funcs):
50 | plot_number = count + 1
51 | plt.subplot(self.rows, self.cols, plot_number)
52 | plt.cla() # clear the previous frame
53 | func()
54 | plt.pause(self.framerate)
55 |
56 | # prep for the next frame, by removing all the functions
57 | self.funcs = []
58 |
--------------------------------------------------------------------------------
/PythonWorkspace/simpleTest.py:
--------------------------------------------------------------------------------
1 | # Copyright 2006-2014 Coppelia Robotics GmbH. All rights reserved.
2 | # marc@coppeliarobotics.com
3 | # www.coppeliarobotics.com
4 | #
5 | # -------------------------------------------------------------------
6 | # THIS FILE IS DISTRIBUTED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
7 | # WARRANTY. THE USER WILL USE IT AT HIS/HER OWN RISK. THE ORIGINAL
8 | # AUTHORS AND COPPELIA ROBOTICS GMBH WILL NOT BE LIABLE FOR DATA LOSS,
9 | # DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR
10 | # MISUSING THIS SOFTWARE.
11 | #
12 | # You are free to use/modify/distribute this file for whatever purpose!
13 | # -------------------------------------------------------------------
14 | #
15 | # This file was automatically created for V-REP release V3.1.3 on Sept. 30th 2014
16 |
17 | # Make sure to have the server side running in V-REP:
18 | # in a child script of a V-REP scene, add following command
19 | # to be executed just once, at simulation start:
20 | #
21 | # simExtRemoteApiStart(19999)
22 | #
23 | # then start simulation, and run this program.
24 | #
25 | # IMPORTANT: for each successful call to simxStart, there
26 | # should be a corresponding call to simxFinish at the end!
27 |
28 | import vrep
29 |
30 | print 'Program started'
31 | vrep.simxFinish(-1) # just in case, close all opened connections
32 | clientID=vrep.simxStart('127.0.0.1',19999,True,True,5000,5)
33 | if clientID!=-1:
34 | print 'Connected to remote API server'
35 | res,objs=vrep.simxGetObjects(clientID,vrep.sim_handle_all,vrep.simx_opmode_oneshot_wait)
36 | if res==vrep.simx_return_ok:
37 | print 'Number of objects in the scene: ',len(objs)
38 | else:
39 | print 'Remote API function call returned with error code: ',res
40 | vrep.simxFinish(clientID)
41 | else:
42 | print 'Failed connecting to remote API server'
43 | print 'Program ended'
44 |
--------------------------------------------------------------------------------
/PythonWorkspace/ringbuffer.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | class RingBuffer():
4 | """ A 1D ring buffer using numpy arrays
5 | inspired by: https://scimusing.wordpress.com/2013/10/25/ring-buffers-in-pythonnumpy/
6 | """
7 | def __init__(self, length):
8 | self.data = np.zeros(length, dtype='f')
9 | self.index = 0
10 | self.weights = np.ones(self.data.size)
11 |
12 | def append(self, x):
13 | "adds element x to ring buffer"
14 | x_index = (self.index - 1) % self.data.size
15 | self.data[x_index] = x
16 | self.index += 1
17 |
18 | def extend(self, x):
19 | "adds array x to ring buffer"
20 | x_index = (self.index + np.arange(x.size)) % self.data.size
21 | self.data[x_index] = x
22 | self.index = x_index[-1] + 1
23 |
24 | def get(self):
25 | "Returns the first-in-first-out data in the ring buffer"
26 | idx = (self.index + np.arange(self.data.size)) %self.data.size
27 | return self.data[idx]
28 |
29 | def weighted_average(self, scheme, mathfunc=lambda x: x):
30 | "choose from same, no weighting"
31 | if scheme == 'same':
32 | self.weights = np.ones(self.data.size)
33 | elif scheme == "last":
34 | for idx, weight in enumerate(range(1, self.data.size + 1)):
35 | self.weights[(self.index + idx) % self.data.size] = mathfunc(weight)
36 |
37 | return np.sum(self.data * self.weights) / np.sum(self.weights)
38 |
39 | def __len__(self):
40 | return self.data.size
41 |
42 | def __iter__(self):
43 | for count in range(self.index, self.index + self.data.size):
44 | yield self.data[count % self.data.size]
45 |
46 | def __getitem__(self, idx):
47 | return self.data[idx % self.data.size]
48 |
49 | def __sum__(self):
50 | return np.sum(self.data)
51 |
52 | if __name__ == '__main__':
53 | rb = RingBuffer(5)
54 |
55 | for i in range(14):
56 | # for i in np.random.rand(15):
57 | rb.append(i)
58 | print rb.index % rb.data.size, rb.data, rb.weighted_average('same'), rb.weighted_average('last'), rb.weighted_average('lastsquared')
59 |
60 | for elem in rb:
61 | print elem
--------------------------------------------------------------------------------
/PythonWorkspace/datastructs.py:
--------------------------------------------------------------------------------
1 | from Queue import heapq
2 | from collections import defaultdict
3 | from json import loads, dumps, dump
4 |
5 |
6 | class PriorityQueueSet(object):
7 | """ Combined priority queue and set data structure. Acts like
8 | a priority queue, except that its items are guaranteed to
9 | be unique.
10 |
11 | Provides O(1) membership test, O(log N) insertion and
12 | O(log N) removal of the smallest item.
13 |
14 | Important: the items of this data structure must be both
15 | comparable and hashable (i.e. must implement __cmp__ and
16 | __hash__). This is true of Python's built-in objects, but
17 | you should implement those methods if you want to use
18 | the data structure for custom objects.
19 |
20 | Adapted from function found on SO:
21 | http://stackoverflow.com/questions/407734/a-generic-priority-queue-for-python
22 | """
23 | def __init__(self, items=[]):
24 | """ Create a new PriorityQueueSet.
25 |
26 | items:
27 | An initial item list - it can be unsorted and
28 | non-unique. The data structure will be created in
29 | O(N).
30 | """
31 | self.set = dict((item, True) for item in items)
32 | self.heap = self.set.keys()
33 | heapq.heapify(self.heap)
34 |
35 | def contains(self, item):
36 | """ Check if *item* exists in the queue
37 | """
38 | return item in self.set
39 |
40 | def empty(self):
41 | if len(self.set) > 0:
42 | return False
43 | else:
44 | return True
45 |
46 | def get(self):
47 | """ Remove and return the smallest item from the queue
48 | """
49 | smallest = heapq.heappop(self.heap)
50 | del self.set[smallest]
51 | return smallest
52 |
53 | def put(self, item):
54 | """ Add *item* to the queue. The item will be added only
55 | if it doesn't already exist in the queue.
56 | """
57 | if not (item in self.set):
58 | self.set[item] = True
59 | heapq.heappush(self.heap, item)
60 |
61 |
62 | class Tree(defaultdict):
63 | """ awesome reddit:
64 | https://gist.github.com/obeleh/4451005
65 | """
66 | def __init__(self, parent=None):
67 | self.parent = parent
68 | defaultdict.__init__(self, lambda: Tree(self))
69 |
70 | def __str__(self, *args, **kwargs):
71 | return dumps(self, sort_keys=True, indent=4)
72 |
73 | if __name__ == "__main__":
74 | a = Tree()
75 | a['1']['2'] = 3
76 | a['1']['3']['4'] = 4
77 | print a['1']['3']
78 | print a['1']['3'].parent
79 | print a['1']['3'].parent.parent
80 | print a['1'].parent
81 | b = Tree({"1": 1, "2": {"1": 3}})
82 | print b
83 | c = Tree('{"1": 1, "2": {"1": 3}}')
84 | print c
--------------------------------------------------------------------------------
/PythonWorkspace/Lab2Program.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | """
3 | Name: Ryan Louie
4 | Student No.: A0149643X
5 | Date: Feb 11th 2016
6 | Version: 0.0.1
7 | """
8 | #Import Libraries:
9 | import vrep #import library for VREP API
10 | import time
11 | import math
12 | import numpy as np #array library
13 | import matplotlib.pyplot as plt #used for image plotting
14 | import skimage.transform
15 | import skimage.filters
16 | from scipy.spatial.distance import cityblock, euclidean
17 | import signal
18 | import sys
19 | from json import load, dump
20 |
21 | from datastructs import PriorityQueueSet, Tree
22 | from idash import IDash
23 | from ringbuffer import RingBuffer
24 |
25 | sys.setrecursionlimit(100000)
26 |
27 | # interactive plotting
28 | plt.ion()
29 |
30 | def format_vrep_image(resolution, image):
31 | im = np.array(image, dtype=np.uint8)
32 | im.resize([resolution[1],resolution[0],3])
33 | return im
34 |
35 | def image_vert_flip(im):
36 | return im[::-1,:,:]
37 |
38 | def prox_sens_initialize(clientID):
39 | """ Initialize proximity sensor. Maybe helpful later """
40 | proxSens=[]
41 | for i in range(8):
42 | _, oneProxSens = vrep.simxGetObjectHandle(clientID, 'ePuck_proxSensor%d' % (i+1), vrep.simx_opmode_streaming)
43 | proxSens.append(oneProxSens)
44 | return proxSens
45 |
46 | def prox_sens_read(clientID, proxSens):
47 | """ Read the proximity sensor
48 | clientID: vrep clientID
49 | proxSens: array of proxSensor handles
50 | """
51 | outputs = []
52 | keys = ('returnCode','detectionState','detectedPoint','detectedObjectHandle','detectedSurfaceNormalVector')
53 | # NOTE: take norm of deteected point to get the distance
54 | for i in range(8):
55 | proxOut=vrep.simxReadProximitySensor(clientID, proxSens[i], vrep.simx_opmode_streaming)
56 | outputs.append(dict(zip(keys, proxOut)))
57 | return outputs
58 |
59 | def odom2pixelmap(x, y, odom_range, map_side_length):
60 | """ Converts xyz in odom to the estimated pixel in the map.
61 | In odom, (0, 0, 0) is in the middle of the pixelmap
62 |
63 | Parameters
64 | ----------
65 | odom_range: the max magnitude of the odom vector along one of the axis
66 | map_side_length: the length of one side of the map
67 |
68 | Returns
69 | -------
70 | (m, n) coordinates of the pixels
71 | """
72 |
73 | # flip odom to have 0 be top left hand corner (currently bottom left)
74 | y *= -1
75 |
76 | # transform odom to no negative coordinates
77 | x += odom_range
78 | y += odom_range
79 |
80 | # scale from odom coords to the map coords
81 | odom_side_length = odom_range * 2
82 | scaling_factor = (float(map_side_length) / odom_side_length)
83 | x *= scaling_factor
84 | y *= scaling_factor
85 |
86 | return int(round(y)), int(round(x))
87 |
88 | def vomega2bytecodes(v, omega, g, L=0.216):
89 | """
90 | Turns v and omega into control codes for differential drive robot
91 | v: forward velocity
92 | omega: angular velocity
93 | g: gain constant
94 | L: length of axle, default .216
95 | >>> right = -1.9914
96 | >>> left = -2.2074
97 | >>> right - left
98 | 0.21599999999999975
99 | """
100 | v_comm = v
101 | v_diff = omega * L / 2.0
102 | ctrl_sig_left = (v_comm - v_diff) / float(g)
103 | ctrl_sig_right = (v_comm + v_diff) / float(g)
104 | return ctrl_sig_left, ctrl_sig_right
105 |
106 | class ThetaRange(object):
107 | @staticmethod
108 | def normalize_angle_pos(angle):
109 | return ((angle % (2*np.pi)) + 2*np.pi) % (2*np.pi)
110 |
111 | @staticmethod
112 | def normalize_angle(angle):
113 | """ Constrains the angles to the range [0, pi) U [-pi, 0) """
114 | a = ThetaRange.normalize_angle_pos(angle)
115 | if a >= np.pi:
116 | a -= 2*np.pi
117 | return a
118 |
119 | def angle_diff(a, b):
120 | """ Calculates the difference between angle a and angle b (both should be in radians)
121 | the difference is always based on the closest rotation from angle a to angle b
122 | examples:
123 | angle_diff(.1,.2) -> -.1
124 | angle_diff(.1, 2*math.pi - .1) -> .2
125 | angle_diff(.1, .2+2*math.pi) -> -.1
126 | """
127 | a = ThetaRange.normalize_angle(a)
128 | b = ThetaRange.normalize_angle(b)
129 | d1 = a-b
130 | d2 = 2*math.pi - math.fabs(d1)
131 | if d1 > 0:
132 | d2 *= -1.0
133 | if math.fabs(d1) < math.fabs(d2):
134 | return d1
135 | else:
136 | return d2
137 |
138 | def test_angle_diff():
139 | angles = np.linspace(-np.pi, np.pi, 64)
140 | theta1s = np.linspace(-np.pi, np.pi, 8)
141 | for count, theta1 in enumerate(theta1s):
142 | diffs = []
143 | for theta0 in angles:
144 | diffs.append(angle_diff(theta0, theta1))
145 | plt.subplot(4,2,count)
146 | plt.plot(diffs)
147 | plt.pause(15)
148 |
149 | # test_angle_diff()
150 |
151 | def ray_trace(paths, m, n, fr, compute_next_cell):
152 | """
153 | paths: a map of binary values, where True denotes pixels where robot can go (not walls)
154 | m: current position, row pixel
155 | n: current position, col pixel
156 | fr: firing range of your ray trace
157 | compute_next_cell: a function handle to how to compute
158 | """
159 | hit_wall = False
160 | count = 1
161 | while (not hit_wall and count <= fr):
162 | next_cell = compute_next_cell(m,n,count)
163 | if paths[next_cell] == False:
164 | hit_wall = True
165 | else:
166 | count += 1
167 | return count
168 |
169 | def pseudoLidarSensor(paths, m, n, fr, original_four):
170 |
171 | if original_four:
172 | functions = [
173 | lambda m, n, count: (m, n+count),
174 | lambda m, n, count: (m-count, n),
175 | lambda m, n, count: (m, n-count),
176 | lambda m, n, count: (m+count, n)
177 | ]
178 | lidarValues = [
179 | ray_trace(paths, m, n, fr, func)
180 | for func in functions
181 | ]
182 |
183 | else:
184 | functions = [
185 | lambda m, n, count: (m, n+count),
186 | lambda m, n, count: (m-count,n+count),
187 | lambda m, n, count: (m-count, n),
188 | lambda m, n, count: (m-count,n-count),
189 | lambda m, n, count: (m, n-count),
190 | lambda m, n, count: (m+count,n-count),
191 | lambda m, n, count: (m+count, n),
192 | lambda m, n, count: (m+count,n+count)
193 | ]
194 | lidarValues = [
195 | ray_trace(paths, m, n, fr, func)
196 | for func in functions
197 | ]
198 | # but the diagnols should have sqrt(2) more weight
199 | for i in range(len(lidarValues)):
200 | if i % 2 == 1:
201 | lidarValues[i] *= np.sqrt(2)
202 |
203 | return lidarValues
204 |
205 | def cart2pol(x, y):
206 | """ NOTE: arctan2 returns phi in the range [-pi, pi] """
207 | rho = np.sqrt(x**2 + y**2)
208 | phi = np.arctan2(y, x)
209 | return(rho, phi)
210 |
211 | def pol2cart(rho, phi):
212 | """ where rho is the Radius, and phi is the angle """
213 | x = rho * np.cos(phi)
214 | y = rho * np.sin(phi)
215 | return(x, y)
216 |
217 | def test_pol2cart2pol():
218 | # pol2cart
219 | rho = 1
220 | angles = np.linspace(0, 2*np.pi, 64)
221 | xs, ys = zip(*[pol2cart(rho, angle) for angle in angles])
222 |
223 | plt.subplot(3,1,1)
224 | plt.plot(angles)
225 |
226 | # cart2pol
227 | new_rhos, new_angles = zip(*[cart2pol(x,y) for x, y in zip(xs, ys)])
228 | plt.subplot(3,1,2)
229 | plt.plot(new_angles)
230 | plt.subplot(3,1,3)
231 | plt.plot([ThetaRange.normalize_angle(ang) for ang in angles])
232 | plt.pause(15)
233 |
234 | # test_pol2cart2pol()
235 |
236 | def mapTheta2worldTheta(mapTheta, northTheta):
237 | """ converts the mapTheta where
238 |
239 | mapTheta = 0 is "east"
240 | mapTheta = pi / 2 is "north"
241 | and mapTheta defined on [0, 2*np.pi)
242 |
243 | to the worldTheta, where
244 | "north" is given by northTheta
245 | and worldTheta defined on [0, pi) U [-pi, 0) """
246 |
247 | # to convert mapTheta pi/2 which is north, to northTheta, we have to do add a bias
248 | bias = northTheta - np.pi / 2
249 |
250 | worldTheta = ThetaRange.normalize_angle(mapTheta + bias)
251 | return worldTheta
252 |
253 | def test_mapTheta2worldTheta():
254 | """ if north Theta given by 0 ..."""
255 | northTheta = 0
256 | # east
257 | assert (mapTheta2worldTheta(0, northTheta) == -np.pi / 2)
258 | # north
259 | assert (mapTheta2worldTheta(1*np.pi/2, northTheta) == 0)
260 | # west
261 | assert (mapTheta2worldTheta(2*np.pi/2, northTheta) == np.pi / 2)
262 | # south
263 | assert (mapTheta2worldTheta(3*np.pi/2, northTheta) == -np.pi)
264 |
265 | northTheta = -np.pi / 2
266 | # east
267 | assert (mapTheta2worldTheta(0, northTheta) == -np.pi)
268 | # north
269 | assert (mapTheta2worldTheta(1*np.pi/2, northTheta) == -np.pi / 2)
270 | # west
271 | assert (mapTheta2worldTheta(2*np.pi/2, northTheta) == 0)
272 | # south
273 | assert (mapTheta2worldTheta(3*np.pi/2, northTheta) == np.pi / 2)
274 |
275 | # test_mapTheta2worldTheta()
276 |
277 | def worldTheta2mapTheta(worldTheta, northTheta):
278 | # to convert mapTheta pi/2 which is north, to northTheta, we have to do add a bias
279 | bias = ThetaRange.normalize_angle(northTheta - np.pi / 2)
280 |
281 | worldTheta = ThetaRange.normalize_angle(worldTheta - bias)
282 | return worldTheta
283 |
284 | def test_worldTheta2mapTheta():
285 | """ if north Theta given by 0 ..."""
286 | northTheta = 0
287 | # east
288 | print worldTheta2mapTheta(-np.pi / 2, northTheta)
289 | assert ThetaRange.normalize_angle(0) == worldTheta2mapTheta(-np.pi / 2, northTheta)
290 | # north
291 | assert ThetaRange.normalize_angle(1*np.pi/2) == worldTheta2mapTheta(0, northTheta)
292 | # west
293 | assert ThetaRange.normalize_angle(2*np.pi/2) == worldTheta2mapTheta(np.pi / 2, northTheta)
294 | # south
295 | assert ThetaRange.normalize_angle(3*np.pi/2) == worldTheta2mapTheta(-np.pi, northTheta)
296 |
297 | northTheta = -np.pi / 2
298 | # east
299 | assert ThetaRange.normalize_angle(0) == worldTheta2mapTheta(-np.pi, northTheta)
300 | # north
301 | assert ThetaRange.normalize_angle(1*np.pi/2) == worldTheta2mapTheta(-np.pi / 2, northTheta)
302 | # west
303 | assert ThetaRange.normalize_angle(2*np.pi/2) ==worldTheta2mapTheta(0, northTheta)
304 | # south
305 | assert ThetaRange.normalize_angle(3*np.pi/2) == worldTheta2mapTheta(np.pi / 2, northTheta)
306 |
307 | # test_worldTheta2mapTheta()
308 |
309 | def force_repulsion(k_repulse, rho, rho_0):
310 | """
311 | k_repulse: positive scaling factor
312 | rho: distance from point to obstacle
313 | rho_0: distance of influence
314 | """
315 | if rho <= rho_0:
316 | return k_repulse*(1.0/rho - 1.0/rho_0)*(1.0/rho**2)
317 | else:
318 | return 0
319 |
320 | def test_force_repulsion():
321 | k_repulse = 10.0
322 | for i, acting_dist in enumerate(range(2,7)):
323 | y = [force_repulsion(k_repulse, val, acting_dist) for val in np.arange(1,7)]
324 | plt.subplot(4,1,i)
325 | plt.plot(y)
326 |
327 | plt.pause(15)
328 |
329 | # test_force_repulsion()
330 |
331 | def tupstring2tuple(tupstring):
332 | """ from '(5,3)' to 5, 3 as integers """
333 | m, n = tupstring.strip('()').split(',')
334 | return int(m), int(n)
335 |
336 | class GracefulKiller:
337 | kill_now = False
338 | def __init__(self):
339 | signal.signal(signal.SIGINT, self.exit_gracefully)
340 | signal.signal(signal.SIGTERM, self.exit_gracefully)
341 |
342 | def exit_gracefully(self,signum, frame):
343 | self.kill_now = True
344 |
345 | class Grid:
346 | def __init__(self, grid):
347 | self.grid = grid
348 | self.shape = grid.shape
349 |
350 | def __getitem__(self, arr):
351 | return self.grid[arr[0], arr[1]]
352 |
353 | def __setitem__(self, idx, val):
354 | self.grid[idx] = val
355 |
356 | class AStarBinaryGrid:
357 | def __init__(self, binary_grid=None, heuristic=cityblock):
358 | """
359 | binary grid: True denoting a valid grid location for the path
360 | heuristic: function handle, which takes two vectors and computes a distance heuristic
361 | """
362 | if binary_grid is None:
363 | self.grid = Grid(np.load('binary_grid.npy'))
364 | else:
365 | assert len(binary_grid.shape) == 2
366 | self.grid = Grid(binary_grid)
367 |
368 | self.heuristic = lambda x, y: heuristic(np.array(x), np.array(y))
369 |
370 | def neighbors_get(self, arr):
371 | directions = [
372 | [0, 1]
373 | , [1, 0]
374 | , [0, -1]
375 | , [-1, 0]
376 | ]
377 | np.random.shuffle(directions)
378 | for direction_vect in directions:
379 | neighbor_cell = np.array(arr) + np.array(direction_vect)
380 | if self.grid[neighbor_cell]:
381 | yield (neighbor_cell[0], neighbor_cell[1])
382 |
383 | def calculate_path(self, start, finish):
384 | assert (len(start) == 2)
385 | assert (len(finish) == 2)
386 | start = (start[0], start[1])
387 | finish = (finish[0], finish[1])
388 | assert self.grid[start] # start is valid
389 | assert self.grid[finish] # finish is valid
390 | g_cost = Grid(np.zeros(self.grid.shape))
391 |
392 | g_cost[start] = 0
393 |
394 | # Priority Queues:
395 | # The lowest valued entries are retrieved first (the lowest valued entry is the one returned by sorted(list(entries))[0]).
396 | # A typical pattern for entries is a tuple in the form: (priority_number, data).
397 | to_visit = PriorityQueueSet()
398 | to_visit.put((
399 | self.heuristic(start, finish),
400 | start
401 | ))
402 | dead_nodes = []
403 | path = []
404 | path.append(start)
405 | tree = Tree()
406 | nested_tree = tree
407 | while not(to_visit.empty()):
408 | (priority_number, current) = to_visit.get()
409 | if self.heuristic(current, finish) == 0.0:
410 | print "Goal Found!"
411 | break
412 | nested_tree = nested_tree[str(current)]
413 | for neigh in self.neighbors_get(current):
414 | # let leaves equal pixel tuples; they will replaces in the next call
415 |
416 | condA = (neigh not in dead_nodes) # not dead, still valid
417 | condB = (not to_visit.contains(neigh)) # we don't have it on our todo list yet
418 | condC = (g_cost[current] + 1 < g_cost[neigh]) # we can get to this neighbor in less cost via our current path
419 | if condA and (condB or condC):
420 | nested_tree[str(neigh)] = Tree()
421 | g_cost[neigh] = g_cost[current] + 1 # cost of neighbor increases by one, since its one move farther away from start
422 | to_visit.put((
423 | g_cost[current] + 1 + self.heuristic(neigh, finish), # one move farther from start + heuristic distance from finish
424 | neigh
425 | ))
426 | dead_nodes.append(current)
427 |
428 |
429 | filepath = 'GOALS.json'
430 | def rememberChain(t, chain):
431 | if len(t) > 0:
432 | for node in t.iterkeys():
433 | chain.append(node)
434 | if node == str(finish):
435 | print "FOUND THE FUCKING CHAIN WHY CANT I RETURN IT: \n",chain
436 | dump(chain, open(filepath, 'w'))
437 | else:
438 | rememberChain(t[node], chain)
439 |
440 | rememberChain(tree, [])
441 | # tree.selfParams(finish, filepath)
442 | # tree.rememberChain([])
443 | goal_strings = load(open(filepath, 'r'))
444 | GOALS = [tupstring2tuple(tupstring) for tupstring in goal_strings]
445 | return GOALS
446 |
447 | def plot(self, pixels_to_mark=None):
448 | im = self.grid.grid*1.0
449 | if pixels_to_mark is None:
450 | pass
451 | else:
452 | for pix in pixels_to_mark:
453 | im[pix] = 0.5
454 | plt.imshow(im)
455 | plt.pause(15)
456 |
457 | astar = AStarBinaryGrid(heuristic=cityblock)
458 | start_pix = (40+2,6)
459 | finish_pix = (5,55)
460 | GOALS = astar.calculate_path(start_pix, finish_pix)
461 | astar.plot(GOALS)
462 |
463 | class Lab2Program:
464 |
465 | def __init__(self):
466 | self.initialize_vrep_client()
467 | self.initilize_vrep_api()
468 | self.define_constants()
469 | self.killer = GracefulKiller()
470 | self.idash = IDash(framerate=0.05)
471 |
472 | def initialize_vrep_client(self):
473 | #Initialisation for Python to connect to VREP
474 | print 'Python program started'
475 | count = 0
476 | num_tries = 10
477 | while count < num_tries:
478 | vrep.simxFinish(-1) # just in case, close all opened connections
479 | self.clientID=vrep.simxStart('127.0.0.1',19999,True,True,5000,5) #Timeout=5000ms, Threadcycle=5ms
480 | if self.clientID!=-1:
481 | print 'Connected to V-REP'
482 | break
483 | else:
484 | "Trying again in a few moments..."
485 | time.sleep(3)
486 | count += 1
487 | if count >= num_tries:
488 | print 'Failed connecting to V-REP'
489 | vrep.simxFinish(self.clientID)
490 |
491 | def initilize_vrep_api(self):
492 | # initialize ePuck handles and variables
493 | _, self.bodyelements=vrep.simxGetObjectHandle(
494 | self.clientID, 'ePuck_bodyElements', vrep.simx_opmode_oneshot_wait)
495 | _, self.leftMotor=vrep.simxGetObjectHandle(
496 | self.clientID, 'ePuck_leftJoint', vrep.simx_opmode_oneshot_wait)
497 | _, self.rightMotor=vrep.simxGetObjectHandle(
498 | self.clientID, 'ePuck_rightJoint', vrep.simx_opmode_oneshot_wait)
499 | _, self.ePuck=vrep.simxGetObjectHandle(
500 | self.clientID, 'ePuck', vrep.simx_opmode_oneshot_wait)
501 | _, self.ePuckBase=vrep.simxGetObjectHandle(
502 | self.clientID, 'ePuck_base', vrep.simx_opmode_oneshot_wait)
503 | # proxSens = prox_sens_initialize(self.clientID)
504 | # initialize odom of ePuck
505 | _, self.xyz = vrep.simxGetObjectPosition(
506 | self.clientID, self.ePuck, -1, vrep.simx_opmode_streaming)
507 | _, self.eulerAngles = vrep.simxGetObjectOrientation(
508 | self.clientID, self.ePuck, -1, vrep.simx_opmode_streaming)
509 |
510 | # initialize overhead cam
511 | _, self.overheadCam=vrep.simxGetObjectHandle(
512 | self.clientID, 'Global_Vision', vrep.simx_opmode_oneshot_wait)
513 | _, self.resolution, self.image = vrep.simxGetVisionSensorImage(
514 | self.clientID,self.overheadCam,0,vrep.simx_opmode_oneshot_wait)
515 |
516 | # initialize goal handle + odom
517 | _, self.goalHandle=vrep.simxGetObjectHandle(
518 | self.clientID, 'Goal_Position', vrep.simx_opmode_oneshot_wait)
519 | _, self.goalPose = vrep.simxGetObjectPosition(
520 | self.clientID, self.goalHandle, -1, vrep.simx_opmode_streaming)
521 |
522 | # STOP Motor Velocities. Not sure if this is necessary
523 | _ = vrep.simxSetJointTargetVelocity(
524 | self.clientID,self.leftMotor,0,vrep.simx_opmode_oneshot_wait)
525 | _ = vrep.simxSetJointTargetVelocity(
526 | self.clientID,self.rightMotor,0,vrep.simx_opmode_oneshot_wait)
527 |
528 | def define_constants(self):
529 | self.map_side_length = 2.55
530 | # FIMXE: hard coded goals
531 | # self.GOALS = [(40+2,6), (40, 6+2), (40,21), (35, 19), (30,22), (29,10), (27,5), (20,8), (20,33), (20, 48), (5,55)]
532 | self.GOALS = None
533 | self.worldNorthTheta = None
534 | self.maxVelocity = 2.0
535 | self.history_length = 5
536 | self.theta_history = RingBuffer(self.history_length)
537 | self.e_theta_h = RingBuffer(self.history_length)
538 | self.blurred_paths = None
539 | self.path_skip = 8
540 |
541 | def global_map_preprocess(self, resolution, image):
542 | im = format_vrep_image(resolution, image) # original image
543 | im = image_vert_flip(im)
544 | resize_length = int(im.shape[0]/2)
545 | im = skimage.transform.resize(im, (resize_length, resize_length, 3))
546 | return im
547 |
548 | def global_map_process(self, im):
549 | walls = im[:,:,0] > 0.25
550 | paths = walls < 0.15
551 | if self.blurred_paths is None:
552 | print "Computed"
553 | blurred_map = skimage.filters.gaussian_filter(walls, sigma=2)
554 | blurred_paths = blurred_map < 0.15
555 | # np.save('binary_grid.npy', blurred_paths)
556 | return paths, blurred_paths
557 | else:
558 | return paths, self.blurred_paths
559 |
560 | def robot_pose_get(self):
561 | _, xyz = vrep.simxGetObjectPosition(
562 | self.clientID, self.ePuck, -1, vrep.simx_opmode_buffer)
563 | _, eulerAngles = vrep.simxGetObjectOrientation(
564 | self.clientID, self.ePuck, -1, vrep.simx_opmode_buffer)
565 | x, y, z = xyz
566 | theta = eulerAngles[2]
567 | self.theta_history.append(theta)
568 |
569 | return (x, y, theta)
570 |
571 | def lidar_scan_get(self, window_size=21):
572 | """ gets lidar scan range values """
573 | fr = (window_size - 1) / 2 # fire range
574 | lidarValues = pseudoLidarSensor(self.paths, self.pose[0], self.pose[1], fr, original_four=False)
575 | return lidarValues
576 |
577 | def repulsion_vectors_compute(self, lidarValues, k_repulse=10.0):
578 | numLidarValues = len(lidarValues)
579 | lidarAngles = [np.pi / numLidarValues * index for index in range(numLidarValues)]
580 |
581 | repulsionVectors = [np.array(pol2cart(force_repulsion(k_repulse, np.sqrt(val), 2), angle)) for val, angle in zip(lidarValues, lidarAngles)]
582 |
583 | return repulsionVectors
584 |
585 | def attraction_vector_compute(self, k_attract=100.0):
586 | self.attractionVal, self.attractionAngle = cart2pol(
587 | self.goal_pose_pixel[1] - self.pose_pixel[1], # cols counts same to normal horz axes
588 | self.pose_pixel[0] - self.goal_pose_pixel[0] # rows counts opposite to normal vert axes
589 | )
590 | attractionVector = np.array(pol2cart(k_attract*self.attractionVal, self.attractionAngle))
591 | return attractionVector
592 |
593 | def robot_code(self):
594 | t = time.time()
595 |
596 | self.curr_goal = 0
597 | while (time.time() - t) < 200:
598 |
599 | # global map
600 | _,resolution,image = vrep.simxGetVisionSensorImage(self.clientID,self.overheadCam,0,vrep.simx_opmode_oneshot_wait) # Get image
601 | im = self.global_map_preprocess(resolution, image)
602 |
603 | self.pose = self.robot_pose_get()
604 | x, y, theta = self.pose
605 | # theta = self.theta_history.weighted_average(scheme='last', mathfunc=lambda x: np.exp(x))
606 |
607 | # initialize worldNorthTheta for the first time
608 | if self.worldNorthTheta is None:
609 | self.worldNorthTheta = self.pose[2]
610 | _ = [self.theta_history.append(self.pose[2]) for _ in range(self.history_length)]
611 |
612 | self.pose_pixel = np.array(odom2pixelmap(x, y, self.map_side_length, im.shape[0]))
613 | m, n = self.pose_pixel
614 |
615 |
616 | self.paths, self.blurred_paths = self.global_map_process(im)
617 |
618 | # calculate intermediate goals once
619 | if self.GOALS is None:
620 | raw_input("")
621 | # acquire pixel location of goal
622 | _, finishPose = vrep.simxGetObjectPosition(
623 | self.clientID, self.goalHandle, -1, vrep.simx_opmode_buffer)
624 | self.finish_pixel = odom2pixelmap(finishPose[0], finishPose[1], self.map_side_length, im.shape[0])
625 | contiguousPath = AStarBinaryGrid(self.blurred_paths).calculate_path(self.pose_pixel, self.finish_pixel)
626 | self.GOALS = contiguousPath[::self.path_skip]
627 | # SKIP THIS FIRST LOOP AND CONTINUE
628 | continue
629 | else:
630 | self.goal_pose_pixel = np.array(self.GOALS[self.curr_goal])
631 | goal_m, goal_n = self.goal_pose_pixel
632 | lidarValues = self.lidar_scan_get(window_size=21)
633 |
634 |
635 | #############################
636 | # Potential Field Algorithm #
637 | #############################
638 | repulsionVectors = self.repulsion_vectors_compute(lidarValues, k_repulse=10.0)
639 | attractionVector = self.attraction_vector_compute(k_attract=100.0)
640 |
641 | finalVector = np.sum(np.vstack((repulsionVectors, attractionVector)), axis=0)
642 | finalUnitVector = finalVector / np.linalg.norm(finalVector)
643 | print "finalUnitVector: ", finalUnitVector
644 |
645 | # TODO: do we use the unit vector (for direction) only, or the finalVector?
646 | finalValue, finalAngle = cart2pol(finalUnitVector[0], finalUnitVector[1])
647 |
648 | error_theta = angle_diff(mapTheta2worldTheta(finalAngle, self.worldNorthTheta), theta)
649 | self.e_theta_h.append(error_theta)
650 |
651 | k_angular_p = 2.0 * self.maxVelocity
652 | k_angular_D = 0.25
653 | k_angular_S = 1.0
654 | k_angular_I = 2.5
655 | omega = k_angular_p * (
656 | error_theta
657 | + k_angular_D / k_angular_S * (self.e_theta_h[-1] - self.e_theta_h[-2])
658 | + k_angular_S / k_angular_I * sum(self.e_theta_h)
659 | )
660 | print "Omega: ", round(omega,1)
661 |
662 | #############################
663 | # StateController Algorithm #
664 | #############################
665 | # if desired heading is not directly in front
666 | if np.abs(error_theta) > np.pi / 3:
667 | # turn in place
668 | forward_vel = self.maxVelocity
669 | # omega *= 0.25
670 | else:
671 | # Direct yourself to the goal
672 | goal_distance = np.linalg.norm(self.goal_pose_pixel - self.pose_pixel)
673 | print "distance_from_goal: ", goal_distance
674 | if goal_distance <= 4:
675 | # Achieved Goal!
676 | forward_vel = self.maxVelocity * 0.25 # Slow down to prepare for the next one
677 | self.curr_goal += 1
678 | else:
679 | forward_vel = self.maxVelocity
680 |
681 | # control the motors
682 | ctrl_sig_left, ctrl_sig_right = vomega2bytecodes(forward_vel, omega, g=1)
683 | _ = vrep.simxSetJointTargetVelocity(
684 | self.clientID,self.leftMotor,ctrl_sig_left,vrep.simx_opmode_oneshot_wait) # set left wheel velocity
685 | _ = vrep.simxSetJointTargetVelocity(
686 | self.clientID,self.rightMotor,ctrl_sig_right,vrep.simx_opmode_oneshot_wait) # set right wheel velocity
687 |
688 | self.idash.add(lambda: self.plot_maze(self.blurred_paths*1.0, m, n, goal_m, goal_n))
689 | self.idash.add(lambda: self.plot_maze(im, m, n, goal_m, goal_n))
690 | def plot_current_and_desired_heading():
691 | self.plot_unit_quiver(finalUnitVector, 'r')
692 | self.plot_unit_quiver(pol2cart(1, worldTheta2mapTheta(theta, self.worldNorthTheta)), 'k')
693 | plt.title("Error Theta: %f" % error_theta)
694 | self.idash.add(plot_current_and_desired_heading)
695 | self.idash.add(self.plot_theta_history)
696 |
697 | self.idash.plotframe()
698 |
699 | if self.killer.kill_now:
700 | self.clean_exit()
701 |
702 | def plot_maze(self, im, m, n, goal_m, goal_n):
703 | """ plots the maze, with robot pose and goal pose visualized """
704 | if len(im.shape) == 3:
705 | goal_pixel_values = np.array((1.0, 1.0, 1.0))
706 | robot_pixel_values = np.array((255.0/255.0,192/255.0,203/255.0))
707 | elif len(im.shape) == 2:
708 | goal_pixel_values = 0.5
709 | robot_pixel_values = 0.5
710 | im[goal_m,goal_n] = goal_pixel_values
711 | im[m,n] = robot_pixel_values
712 | plt.imshow(im)
713 |
714 | def plot_unit_quiver(self, vector, color):
715 | X, Y = (0, 0)
716 | U, V = (vector[0], vector[1])
717 | plt.quiver(X,Y,U,V,angles='xy',scale_units='xy',scale=1,color=color)
718 | plt.xlim([-1.1,1.1])
719 | plt.ylim([-1.1,1.1])
720 |
721 | def plot_theta_history(self, expansion=5):
722 | plt.plot([theta for theta in self.theta_history])
723 | if len(self.theta_history) < expansion:
724 | plt.xlim([0, expansion])
725 | else:
726 | plt.xlim([0, len(self.theta_history)])
727 | ylim = np.pi + 0.5
728 | plt.ylim([-ylim, ylim])
729 |
730 | def plot_all_goals(self, im):
731 | # display all goals
732 | for goal_idx in range(len(self.GOALS)):
733 | im[self.GOALS[goal_idx][0], self.GOALS[goal_idx][1]] = np.array((1.0, 1.0, 1.0))
734 |
735 | def clean_exit(self):
736 | _ = vrep.simxStopSimulation(self.clientID,vrep.simx_opmode_oneshot_wait)
737 | vrep.simxFinish(self.clientID)
738 | print 'Program ended'
739 | sys.exit(0)
740 |
741 | def run(self):
742 | if self.clientID!=-1:
743 | _ = vrep.simxStartSimulation(self.clientID,vrep.simx_opmode_oneshot_wait)
744 | self.robot_code()
745 |
746 | self.clean_exit()
747 |
748 | if __name__ == '__main__':
749 | obj = Lab2Program()
750 | obj.run()
751 |
--------------------------------------------------------------------------------
/PythonWorkspace/vrepConst.py:
--------------------------------------------------------------------------------
1 | # This file is part of the REMOTE API
2 | #
3 | # Copyright 2006-2015 Coppelia Robotics GmbH. All rights reserved.
4 | # marc@coppeliarobotics.com
5 | # www.coppeliarobotics.com
6 | #
7 | # The REMOTE API is licensed under the terms of GNU GPL:
8 | #
9 | # -------------------------------------------------------------------
10 | # The REMOTE API is free software: you can redistribute it and/or modify
11 | # it under the terms of the GNU General Public License as published by
12 | # the Free Software Foundation, either version 3 of the License, or
13 | # (at your option) any later version.
14 | #
15 | # THE REMOTE API IS DISTRIBUTED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
16 | # WARRANTY. THE USER WILL USE IT AT HIS/HER OWN RISK. THE ORIGINAL
17 | # AUTHORS AND COPPELIA ROBOTICS GMBH WILL NOT BE LIABLE FOR DATA LOSS,
18 | # DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR
19 | # MISUSING THIS SOFTWARE.
20 | #
21 | # See the GNU General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU General Public License
24 | # along with the REMOTE API. If not, see .
25 | # -------------------------------------------------------------------
26 | #
27 | # This file was automatically created for V-REP release V3.2.3 rev4 on December 21st 2015
28 |
29 | #constants
30 | #Scene object types. Values are serialized
31 | sim_object_shape_type =0
32 | sim_object_joint_type =1
33 | sim_object_graph_type =2
34 | sim_object_camera_type =3
35 | sim_object_dummy_type =4
36 | sim_object_proximitysensor_type =5
37 | sim_object_reserved1 =6
38 | sim_object_reserved2 =7
39 | sim_object_path_type =8
40 | sim_object_visionsensor_type =9
41 | sim_object_volume_type =10
42 | sim_object_mill_type =11
43 | sim_object_forcesensor_type =12
44 | sim_object_light_type =13
45 | sim_object_mirror_type =14
46 |
47 | #General object types. Values are serialized
48 | sim_appobj_object_type =109
49 | sim_appobj_collision_type =110
50 | sim_appobj_distance_type =111
51 | sim_appobj_simulation_type =112
52 | sim_appobj_ik_type =113
53 | sim_appobj_constraintsolver_type=114
54 | sim_appobj_collection_type =115
55 | sim_appobj_ui_type =116
56 | sim_appobj_script_type =117
57 | sim_appobj_pathplanning_type =118
58 | sim_appobj_RESERVED_type =119
59 | sim_appobj_texture_type =120
60 |
61 | # Ik calculation methods. Values are serialized
62 | sim_ik_pseudo_inverse_method =0
63 | sim_ik_damped_least_squares_method =1
64 | sim_ik_jacobian_transpose_method =2
65 |
66 | # Ik constraints. Values are serialized
67 | sim_ik_x_constraint =1
68 | sim_ik_y_constraint =2
69 | sim_ik_z_constraint =4
70 | sim_ik_alpha_beta_constraint=8
71 | sim_ik_gamma_constraint =16
72 | sim_ik_avoidance_constraint =64
73 |
74 | # Ik calculation results
75 | sim_ikresult_not_performed =0
76 | sim_ikresult_success =1
77 | sim_ikresult_fail =2
78 |
79 | # Scene object sub-types. Values are serialized
80 | # Light sub-types
81 | sim_light_omnidirectional_subtype =1
82 | sim_light_spot_subtype =2
83 | sim_light_directional_subtype =3
84 | # Joint sub-types
85 | sim_joint_revolute_subtype =10
86 | sim_joint_prismatic_subtype =11
87 | sim_joint_spherical_subtype =12
88 | # Shape sub-types
89 | sim_shape_simpleshape_subtype =20
90 | sim_shape_multishape_subtype =21
91 | # Proximity sensor sub-types
92 | sim_proximitysensor_pyramid_subtype =30
93 | sim_proximitysensor_cylinder_subtype=31
94 | sim_proximitysensor_disc_subtype =32
95 | sim_proximitysensor_cone_subtype =33
96 | sim_proximitysensor_ray_subtype =34
97 | # Mill sub-types
98 | sim_mill_pyramid_subtype =40
99 | sim_mill_cylinder_subtype =41
100 | sim_mill_disc_subtype =42
101 | sim_mill_cone_subtype =42
102 | # No sub-type
103 | sim_object_no_subtype =200
104 |
105 |
106 | #Scene object main properties (serialized)
107 | sim_objectspecialproperty_collidable =0x0001
108 | sim_objectspecialproperty_measurable =0x0002
109 | #reserved =0x0004
110 | #reserved =0x0008
111 | sim_objectspecialproperty_detectable_ultrasonic =0x0010
112 | sim_objectspecialproperty_detectable_infrared =0x0020
113 | sim_objectspecialproperty_detectable_laser =0x0040
114 | sim_objectspecialproperty_detectable_inductive =0x0080
115 | sim_objectspecialproperty_detectable_capacitive =0x0100
116 | sim_objectspecialproperty_renderable =0x0200
117 | sim_objectspecialproperty_detectable_all =sim_objectspecialproperty_detectable_ultrasonic|sim_objectspecialproperty_detectable_infrared|sim_objectspecialproperty_detectable_laser|sim_objectspecialproperty_detectable_inductive|sim_objectspecialproperty_detectable_capacitive
118 | sim_objectspecialproperty_cuttable =0x0400
119 | sim_objectspecialproperty_pathplanning_ignored =0x0800
120 |
121 | # Model properties (serialized)
122 | sim_modelproperty_not_collidable =0x0001
123 | sim_modelproperty_not_measurable =0x0002
124 | sim_modelproperty_not_renderable =0x0004
125 | sim_modelproperty_not_detectable =0x0008
126 | sim_modelproperty_not_cuttable =0x0010
127 | sim_modelproperty_not_dynamic =0x0020
128 | sim_modelproperty_not_respondable =0x0040 # cannot be selected if sim_modelproperty_not_dynamic is not selected
129 | sim_modelproperty_not_reset =0x0080 # Model is not reset at simulation end. This flag is cleared at simulation end
130 | sim_modelproperty_not_visible =0x0100 # Whole model is invisible independent of local visibility settings
131 | sim_modelproperty_not_model =0xf000 # object is not a model
132 |
133 |
134 | # Check the documentation instead of comments below!!
135 | # Following messages are dispatched to the Lua-message container
136 | sim_message_ui_button_state_change =0 # a UI button slider etc. changed (due to a user's action). aux[0]=UI handle aux[1]=button handle aux[2]=button attributes aux[3]=slider position (if slider)
137 | sim_message_reserved9 =1 # Do not use
138 | sim_message_object_selection_changed=2
139 | sim_message_reserved10 =3 # do not use
140 | sim_message_model_loaded =4
141 | sim_message_reserved11 =5 # do not use
142 | sim_message_keypress =6 # a key was pressed while the focus was on a page (aux[0]=key aux[1]=ctrl and shift key state)
143 | sim_message_bannerclicked =7 # a banner was clicked (aux[0]=banner ID)
144 |
145 |
146 | # Following messages are dispatched only to the C-API (not available from Lua)
147 | sim_message_for_c_api_only_start =0x100 # Do not use
148 | sim_message_reserved1 =0x101 # Do not use
149 | sim_message_reserved2 =0x102 # Do not use
150 | sim_message_reserved3 =0x103 # Do not use
151 | sim_message_eventcallback_scenesave =0x104 # about to save a scene
152 | sim_message_eventcallback_modelsave =0x105 # about to save a model (current selection will be saved)
153 | sim_message_eventcallback_moduleopen =0x106 # called when simOpenModule in Lua is called
154 | sim_message_eventcallback_modulehandle =0x107 # called when simHandleModule in Lua is called with argument false
155 | sim_message_eventcallback_moduleclose =0x108 # called when simCloseModule in Lua is called
156 | sim_message_reserved4 =0x109 # Do not use
157 | sim_message_reserved5 =0x10a # Do not use
158 | sim_message_reserved6 =0x10b # Do not use
159 | sim_message_reserved7 =0x10c # Do not use
160 | sim_message_eventcallback_instancepass =0x10d # Called once every main application loop pass. auxiliaryData[0] contains event flags of events that happened since last time
161 | sim_message_eventcallback_broadcast =0x10e
162 | sim_message_eventcallback_imagefilter_enumreset =0x10f
163 | sim_message_eventcallback_imagefilter_enumerate =0x110
164 | sim_message_eventcallback_imagefilter_adjustparams =0x111
165 | sim_message_eventcallback_imagefilter_reserved =0x112
166 | sim_message_eventcallback_imagefilter_process =0x113
167 | sim_message_eventcallback_reserved1 =0x114 # do not use
168 | sim_message_eventcallback_reserved2 =0x115 # do not use
169 | sim_message_eventcallback_reserved3 =0x116 # do not use
170 | sim_message_eventcallback_reserved4 =0x117 # do not use
171 | sim_message_eventcallback_abouttoundo =0x118 # the undo button was hit and a previous state is about to be restored
172 | sim_message_eventcallback_undoperformed =0x119 # the undo button was hit and a previous state restored
173 | sim_message_eventcallback_abouttoredo =0x11a # the redo button was hit and a future state is about to be restored
174 | sim_message_eventcallback_redoperformed =0x11b # the redo button was hit and a future state restored
175 | sim_message_eventcallback_scripticondblclick =0x11c # scipt icon was double clicked. (aux[0]=object handle associated with script set replyData[0] to 1 if script should not be opened)
176 | sim_message_eventcallback_simulationabouttostart =0x11d
177 | sim_message_eventcallback_simulationended =0x11e
178 | sim_message_eventcallback_reserved5 =0x11f # do not use
179 | sim_message_eventcallback_keypress =0x120 # a key was pressed while the focus was on a page (aux[0]=key aux[1]=ctrl and shift key state)
180 | sim_message_eventcallback_modulehandleinsensingpart =0x121 # called when simHandleModule in Lua is called with argument true
181 | sim_message_eventcallback_renderingpass =0x122 # called just before the scene is rendered
182 | sim_message_eventcallback_bannerclicked =0x123 # called when a banner was clicked (aux[0]=banner ID)
183 | sim_message_eventcallback_menuitemselected =0x124 # auxiliaryData[0] indicates the handle of the item auxiliaryData[1] indicates the state of the item
184 | sim_message_eventcallback_refreshdialogs =0x125 # aux[0]=refresh degree (0=light 1=medium 2=full)
185 | sim_message_eventcallback_sceneloaded =0x126
186 | sim_message_eventcallback_modelloaded =0x127
187 | sim_message_eventcallback_instanceswitch =0x128
188 | sim_message_eventcallback_guipass =0x129
189 | sim_message_eventcallback_mainscriptabouttobecalled =0x12a
190 | sim_message_eventcallback_rmlposition =0x12b #the command simRMLPosition was called. The appropriate plugin should handle the call
191 | sim_message_eventcallback_rmlvelocity =0x12c # the command simRMLVelocity was called. The appropriate plugin should handle the call
192 | sim_message_simulation_start_resume_request =0x1000
193 | sim_message_simulation_pause_request =0x1001
194 | sim_message_simulation_stop_request =0x1002
195 |
196 | # Scene object properties. Combine with the | operator
197 | sim_objectproperty_reserved1 =0x0000
198 | sim_objectproperty_reserved2 =0x0001
199 | sim_objectproperty_reserved3 =0x0002
200 | sim_objectproperty_reserved4 =0x0003
201 | sim_objectproperty_reserved5 =0x0004 # formely sim_objectproperty_visible
202 | sim_objectproperty_reserved6 =0x0008 # formely sim_objectproperty_wireframe
203 | sim_objectproperty_collapsed =0x0010
204 | sim_objectproperty_selectable =0x0020
205 | sim_objectproperty_reserved7 =0x0040
206 | sim_objectproperty_selectmodelbaseinstead =0x0080
207 | sim_objectproperty_dontshowasinsidemodel =0x0100
208 | # reserved =0x0200
209 | sim_objectproperty_canupdatedna =0x0400
210 | sim_objectproperty_selectinvisible =0x0800
211 | sim_objectproperty_depthinvisible =0x1000
212 |
213 |
214 | # type of arguments (input and output) for custom lua commands
215 | sim_lua_arg_nil =0
216 | sim_lua_arg_bool =1
217 | sim_lua_arg_int =2
218 | sim_lua_arg_float =3
219 | sim_lua_arg_string =4
220 | sim_lua_arg_invalid =5
221 | sim_lua_arg_table =8
222 |
223 | # custom user interface properties. Values are serialized.
224 | sim_ui_property_visible =0x0001
225 | sim_ui_property_visibleduringsimulationonly =0x0002
226 | sim_ui_property_moveable =0x0004
227 | sim_ui_property_relativetoleftborder =0x0008
228 | sim_ui_property_relativetotopborder =0x0010
229 | sim_ui_property_fixedwidthfont =0x0020
230 | sim_ui_property_systemblock =0x0040
231 | sim_ui_property_settocenter =0x0080
232 | sim_ui_property_rolledup =0x0100
233 | sim_ui_property_selectassociatedobject =0x0200
234 | sim_ui_property_visiblewhenobjectselected =0x0400
235 |
236 |
237 | # button properties. Values are serialized.
238 | sim_buttonproperty_button =0x0000
239 | sim_buttonproperty_label =0x0001
240 | sim_buttonproperty_slider =0x0002
241 | sim_buttonproperty_editbox =0x0003
242 | sim_buttonproperty_staydown =0x0008
243 | sim_buttonproperty_enabled =0x0010
244 | sim_buttonproperty_borderless =0x0020
245 | sim_buttonproperty_horizontallycentered =0x0040
246 | sim_buttonproperty_ignoremouse =0x0080
247 | sim_buttonproperty_isdown =0x0100
248 | sim_buttonproperty_transparent =0x0200
249 | sim_buttonproperty_nobackgroundcolor =0x0400
250 | sim_buttonproperty_rollupaction =0x0800
251 | sim_buttonproperty_closeaction =0x1000
252 | sim_buttonproperty_verticallycentered =0x2000
253 | sim_buttonproperty_downupevent =0x4000
254 |
255 |
256 | # Simulation status
257 | sim_simulation_stopped =0x00 # Simulation is stopped
258 | sim_simulation_paused =0x08 # Simulation is paused
259 | sim_simulation_advancing =0x10 # Simulation is advancing
260 | sim_simulation_advancing_firstafterstop =sim_simulation_advancing|0x00 # First simulation pass (1x)
261 | sim_simulation_advancing_running =sim_simulation_advancing|0x01 # Normal simulation pass (>=1x)
262 | # reserved =sim_simulation_advancing|0x02
263 | sim_simulation_advancing_lastbeforepause =sim_simulation_advancing|0x03 # Last simulation pass before pause (1x)
264 | sim_simulation_advancing_firstafterpause =sim_simulation_advancing|0x04 # First simulation pass after pause (1x)
265 | sim_simulation_advancing_abouttostop =sim_simulation_advancing|0x05 # "Trying to stop" simulation pass (>=1x)
266 | sim_simulation_advancing_lastbeforestop =sim_simulation_advancing|0x06 # Last simulation pass (1x)
267 |
268 |
269 | # Script execution result (first return value)
270 | sim_script_no_error =0
271 | sim_script_main_script_nonexistent =1
272 | sim_script_main_script_not_called =2
273 | sim_script_reentrance_error =4
274 | sim_script_lua_error =8
275 | sim_script_call_error =16
276 |
277 |
278 | # Script types (serialized!)
279 | sim_scripttype_mainscript =0
280 | sim_scripttype_childscript =1
281 | sim_scripttype_pluginscript =2
282 | sim_scripttype_threaded =0x00f0 # Combine with one of above's type values
283 |
284 | # API call error messages
285 | sim_api_errormessage_ignore =0 # does not memorize nor output errors
286 | sim_api_errormessage_report =1 # memorizes errors (default for C-API calls)
287 | sim_api_errormessage_output =2 # memorizes and outputs errors (default for Lua-API calls)
288 |
289 |
290 | # special argument of some functions
291 | sim_handle_all =-2
292 | sim_handle_all_except_explicit =-3
293 | sim_handle_self =-4
294 | sim_handle_main_script =-5
295 | sim_handle_tree =-6
296 | sim_handle_chain =-7
297 | sim_handle_single =-8
298 | sim_handle_default =-9
299 | sim_handle_all_except_self =-10
300 | sim_handle_parent =-11
301 |
302 |
303 | # special handle flags
304 | sim_handleflag_assembly =0x400000
305 | sim_handleflag_model =0x800000
306 |
307 |
308 | # distance calculation methods (serialized)
309 | sim_distcalcmethod_dl =0
310 | sim_distcalcmethod_dac =1
311 | sim_distcalcmethod_max_dl_dac =2
312 | sim_distcalcmethod_dl_and_dac =3
313 | sim_distcalcmethod_sqrt_dl2_and_dac2=4
314 | sim_distcalcmethod_dl_if_nonzero =5
315 | sim_distcalcmethod_dac_if_nonzero =6
316 |
317 |
318 | # Generic dialog styles
319 | sim_dlgstyle_message =0
320 | sim_dlgstyle_input =1
321 | sim_dlgstyle_ok =2
322 | sim_dlgstyle_ok_cancel =3
323 | sim_dlgstyle_yes_no =4
324 | sim_dlgstyle_dont_center =32# can be combined with one of above values. Only with this flag can the position of the related UI be set just after dialog creation
325 |
326 | # Generic dialog return values
327 | sim_dlgret_still_open =0
328 | sim_dlgret_ok =1
329 | sim_dlgret_cancel =2
330 | sim_dlgret_yes =3
331 | sim_dlgret_no =4
332 |
333 |
334 | # Path properties
335 | sim_pathproperty_show_line =0x0001
336 | sim_pathproperty_show_orientation =0x0002
337 | sim_pathproperty_closed_path =0x0004
338 | sim_pathproperty_automatic_orientation =0x0008
339 | sim_pathproperty_invert_velocity =0x0010
340 | sim_pathproperty_infinite_acceleration =0x0020
341 | sim_pathproperty_flat_path =0x0040
342 | sim_pathproperty_show_position =0x0080
343 | sim_pathproperty_auto_velocity_profile_translation =0x0100
344 | sim_pathproperty_auto_velocity_profile_rotation =0x0200
345 | sim_pathproperty_endpoints_at_zero =0x0400
346 | sim_pathproperty_keep_x_up =0x0800
347 |
348 |
349 | # drawing objects
350 | # following are mutually exclusive
351 | sim_drawing_points =0 # 3 values per point (point size in pixels)
352 | sim_drawing_lines =1 # 6 values per line (line size in pixels)
353 | sim_drawing_triangles =2 # 9 values per triangle
354 | sim_drawing_trianglepoints =3 # 6 values per point (3 for triangle position 3 for triangle normal vector) (triangle size in meters)
355 | sim_drawing_quadpoints =4 # 6 values per point (3 for quad position 3 for quad normal vector) (quad size in meters)
356 | sim_drawing_discpoints =5 # 6 values per point (3 for disc position 3 for disc normal vector) (disc size in meters)
357 | sim_drawing_cubepoints =6 # 6 values per point (3 for cube position 3 for cube normal vector) (cube size in meters)
358 | sim_drawing_spherepoints =7 # 3 values per point (sphere size in meters)
359 |
360 | # following can be or-combined
361 | sim_drawing_itemcolors =0x00020 # +3 values per item (each item has its own ambient color (rgb values)).
362 | # Mutually exclusive with sim_drawing_vertexcolors
363 | sim_drawing_vertexcolors =0x00040 # +3 values per vertex (each vertex has its own ambient color (rgb values). Only for sim_drawing_lines (+6) and for sim_drawing_triangles(+9)). Mutually exclusive with sim_drawing_itemcolors
364 | sim_drawing_itemsizes =0x00080 # +1 value per item (each item has its own size). Not for sim_drawing_triangles
365 | sim_drawing_backfaceculling =0x00100 # back faces are not displayed for all items
366 | sim_drawing_wireframe =0x00200 # all items displayed in wireframe
367 | sim_drawing_painttag =0x00400 # all items are tagged as paint (for additinal processing at a later stage)
368 | sim_drawing_followparentvisibility =0x00800 # if the object is associated with a scene object then it follows that visibility otherwise it is always visible
369 | sim_drawing_cyclic =0x01000 # if the max item count was reached then the first items are overwritten.
370 | sim_drawing_50percenttransparency =0x02000 # the drawing object will be 50% transparent
371 | sim_drawing_25percenttransparency =0x04000 # the drawing object will be 25% transparent
372 | sim_drawing_12percenttransparency =0x08000 # the drawing object will be 12.5% transparent
373 | sim_drawing_emissioncolor =0x10000 # When used in combination with sim_drawing_itemcolors or sim_drawing_vertexcolors then the specified colors will be for the emissive component
374 | sim_drawing_facingcamera =0x20000 # Only for trianglepoints quadpoints discpoints and cubepoints. If specified the normal verctor is calculated to face the camera (each item data requires 3 values less)
375 | sim_drawing_overlay =0x40000 # When specified objects are always drawn on top of "regular objects"
376 | sim_drawing_itemtransparency =0x80000 # +1 value per item (each item has its own transparency value (0-1)). Not compatible with sim_drawing_vertexcolors
377 |
378 | # banner values
379 | # following can be or-combined
380 | sim_banner_left =0x00001 # Banners display on the left of the specified point
381 | sim_banner_right =0x00002 # Banners display on the right of the specified point
382 | sim_banner_nobackground =0x00004 # Banners have no background rectangle
383 | sim_banner_overlay =0x00008 # When specified banners are always drawn on top of "regular objects"
384 | sim_banner_followparentvisibility =0x00010 # if the object is associated with a scene object then it follows that visibility otherwise it is always visible
385 | sim_banner_clickselectsparent =0x00020 # if the object is associated with a scene object then clicking the banner will select the scene object
386 | sim_banner_clicktriggersevent =0x00040 # if the banner is clicked an event is triggered (sim_message_eventcallback_bannerclicked and sim_message_bannerclicked are generated)
387 | sim_banner_facingcamera =0x00080 # If specified the banner will always face the camera by rotating around the banner's vertical axis (y-axis)
388 | sim_banner_fullyfacingcamera =0x00100 # If specified the banner will always fully face the camera (the banner's orientation is same as the camera looking at it)
389 | sim_banner_backfaceculling =0x00200 # If specified the banner will only be visible from one side
390 | sim_banner_keepsamesize =0x00400 # If specified the banner will always appear in the same size. In that case size represents the character height in pixels
391 | sim_banner_bitmapfont =0x00800 # If specified a fixed-size bitmap font is used. The text will also always fully face the camera and be right
392 | # to the specified position. Bitmap fonts are not clickable
393 |
394 |
395 | # particle objects following are mutually exclusive
396 | sim_particle_points1 =0 # 6 values per point (pt1 and pt2. Pt1 is start position pt2-pt1 is the initial velocity vector). i
397 | #Point is 1 pixel big. Only appearance is a point internally handled as a perfect sphere
398 | sim_particle_points2 =1 # 6 values per point. Point is 2 pixel big. Only appearance is a point internally handled as a perfect sphere
399 | sim_particle_points4 =2 # 6 values per point. Point is 4 pixel big. Only appearance is a point internally handled as a perfect sphere
400 | sim_particle_roughspheres =3 # 6 values per sphere. Only appearance is rough. Internally a perfect sphere
401 | sim_particle_spheres =4 # 6 values per sphere. Internally a perfect sphere
402 |
403 |
404 |
405 |
406 | # following can be or-combined
407 | sim_particle_respondable1to4 =0x0020 # the particles are respondable against shapes (against all objects that have at least one bit 1-4 activated in the global respondable mask)
408 | sim_particle_respondable5to8 =0x0040 # the particles are respondable against shapes (against all objects that have at least one bit 5-8 activated in the global respondable mask)
409 | sim_particle_particlerespondable =0x0080 # the particles are respondable against each other
410 | sim_particle_ignoresgravity =0x0100 # the particles ignore the effect of gravity. Not compatible with sim_particle_water
411 | sim_particle_invisible =0x0200 # the particles are invisible
412 | sim_particle_itemsizes =0x0400 # +1 value per particle (each particle can have a different size)
413 | sim_particle_itemdensities =0x0800 # +1 value per particle (each particle can have a different density)
414 | sim_particle_itemcolors =0x1000 # +3 values per particle (each particle can have a different color)
415 | sim_particle_cyclic =0x2000 # if the max item count was reached then the first items are overwritten.
416 | sim_particle_emissioncolor =0x4000 # When used in combination with sim_particle_itemcolors then the specified colors will be for the emissive component
417 | sim_particle_water =0x8000 # the particles are water particles (no weight in the water (i.e. when z<0)). Not compatible with sim_particle_ignoresgravity
418 | sim_particle_painttag =0x10000 # The particles can be seen by vision sensors (sim_particle_invisible must not be set)
419 |
420 |
421 |
422 |
423 | # custom user interface menu attributes
424 | sim_ui_menu_title =1
425 | sim_ui_menu_minimize =2
426 | sim_ui_menu_close =4
427 | sim_ui_menu_systemblock =8
428 |
429 |
430 |
431 | # Boolean parameters
432 | sim_boolparam_hierarchy_visible =0
433 | sim_boolparam_console_visible =1
434 | sim_boolparam_collision_handling_enabled =2
435 | sim_boolparam_distance_handling_enabled =3
436 | sim_boolparam_ik_handling_enabled =4
437 | sim_boolparam_gcs_handling_enabled =5
438 | sim_boolparam_dynamics_handling_enabled =6
439 | sim_boolparam_joint_motion_handling_enabled =7
440 | sim_boolparam_path_motion_handling_enabled =8
441 | sim_boolparam_proximity_sensor_handling_enabled =9
442 | sim_boolparam_vision_sensor_handling_enabled =10
443 | sim_boolparam_mill_handling_enabled =11
444 | sim_boolparam_browser_visible =12
445 | sim_boolparam_scene_and_model_load_messages =13
446 | sim_reserved0 =14
447 | sim_boolparam_shape_textures_are_visible =15
448 | sim_boolparam_display_enabled =16
449 | sim_boolparam_infotext_visible =17
450 | sim_boolparam_statustext_open =18
451 | sim_boolparam_fog_enabled =19
452 | sim_boolparam_rml2_available =20
453 | sim_boolparam_rml4_available =21
454 | sim_boolparam_mirrors_enabled =22
455 | sim_boolparam_aux_clip_planes_enabled =23
456 | sim_boolparam_full_model_copy_from_api =24
457 | sim_boolparam_realtime_simulation =25
458 | sim_boolparam_force_show_wireless_emission =27
459 | sim_boolparam_force_show_wireless_reception =28
460 | sim_boolparam_video_recording_triggered =29
461 | sim_boolparam_threaded_rendering_enabled =32
462 | sim_boolparam_fullscreen =33
463 | sim_boolparam_headless =34
464 | sim_boolparam_hierarchy_toolbarbutton_enabled =35
465 | sim_boolparam_browser_toolbarbutton_enabled =36
466 | sim_boolparam_objectshift_toolbarbutton_enabled =37
467 | sim_boolparam_objectrotate_toolbarbutton_enabled=38
468 | sim_boolparam_force_calcstruct_all_visible =39
469 | sim_boolparam_force_calcstruct_all =40
470 | sim_boolparam_exit_request =41
471 | sim_boolparam_play_toolbarbutton_enabled =42
472 | sim_boolparam_pause_toolbarbutton_enabled =43
473 | sim_boolparam_stop_toolbarbutton_enabled =44
474 | sim_boolparam_waiting_for_trigger =45
475 |
476 |
477 | # Integer parameters
478 | sim_intparam_error_report_mode =0 # Check sim_api_errormessage_... constants above for valid values
479 | sim_intparam_program_version =1 # e.g Version 2.1.4 --> 20104. Can only be read
480 | sim_intparam_instance_count =2 # do not use anymore (always returns 1 since V-REP 2.5.11)
481 | sim_intparam_custom_cmd_start_id =3 # can only be read
482 | sim_intparam_compilation_version =4 # 0=evaluation version 1=full version 2=player version. Can only be read
483 | sim_intparam_current_page =5
484 | sim_intparam_flymode_camera_handle =6 # can only be read
485 | sim_intparam_dynamic_step_divider =7 # can only be read
486 | sim_intparam_dynamic_engine =8 # 0=Bullet 1=ODE. 2=Vortex.
487 | sim_intparam_server_port_start =9 # can only be read
488 | sim_intparam_server_port_range =10 # can only be read
489 | sim_intparam_visible_layers =11
490 | sim_intparam_infotext_style =12
491 | sim_intparam_settings =13
492 | sim_intparam_edit_mode_type =14 # can only be read
493 | sim_intparam_server_port_next =15 # is initialized at sim_intparam_server_port_start
494 | sim_intparam_qt_version =16 # version of the used Qt framework
495 | sim_intparam_event_flags_read =17 # can only be read
496 | sim_intparam_event_flags_read_clear =18 # can only be read
497 | sim_intparam_platform =19 # can only be read
498 | sim_intparam_scene_unique_id =20 # can only be read
499 | sim_intparam_work_thread_count =21
500 | sim_intparam_mouse_x =22
501 | sim_intparam_mouse_y =23
502 | sim_intparam_core_count =24
503 | sim_intparam_work_thread_calc_time_ms =25
504 | sim_intparam_idle_fps =26
505 | sim_intparam_prox_sensor_select_down =27
506 | sim_intparam_prox_sensor_select_up =28
507 | sim_intparam_stop_request_counter =29
508 | sim_intparam_program_revision =30
509 | sim_intparam_mouse_buttons =31
510 | sim_intparam_dynamic_warning_disabled_mask =32
511 | sim_intparam_simulation_warning_disabled_mask =33
512 | sim_intparam_scene_index =34
513 | sim_intparam_motionplanning_seed =35
514 | sim_intparam_speedmodifier =36
515 |
516 | # Float parameters
517 | sim_floatparam_rand=0 # random value (0.0-1.0)
518 | sim_floatparam_simulation_time_step =1
519 | sim_floatparam_stereo_distance =2
520 |
521 | # String parameters
522 | sim_stringparam_application_path=0 # path of V-REP's executable
523 | sim_stringparam_video_filename=1
524 | sim_stringparam_app_arg1 =2
525 | sim_stringparam_app_arg2 =3
526 | sim_stringparam_app_arg3 =4
527 | sim_stringparam_app_arg4 =5
528 | sim_stringparam_app_arg5 =6
529 | sim_stringparam_app_arg6 =7
530 | sim_stringparam_app_arg7 =8
531 | sim_stringparam_app_arg8 =9
532 | sim_stringparam_app_arg9 =10
533 | sim_stringparam_scene_path_and_name =13
534 |
535 | # Array parameters
536 | sim_arrayparam_gravity =0
537 | sim_arrayparam_fog =1
538 | sim_arrayparam_fog_color =2
539 | sim_arrayparam_background_color1=3
540 | sim_arrayparam_background_color2=4
541 | sim_arrayparam_ambient_light =5
542 | sim_arrayparam_random_euler =6
543 |
544 |
545 | # User interface elements
546 | sim_gui_menubar =0x0001
547 | sim_gui_popups =0x0002
548 | sim_gui_toolbar1 =0x0004
549 | sim_gui_toolbar2 =0x0008
550 | sim_gui_hierarchy =0x0010
551 | sim_gui_infobar =0x0020
552 | sim_gui_statusbar =0x0040
553 | sim_gui_scripteditor =0x0080
554 | sim_gui_scriptsimulationparameters =0x0100
555 | sim_gui_dialogs =0x0200
556 | sim_gui_browser =0x0400
557 | sim_gui_all =0xffff
558 |
559 |
560 | # Joint modes
561 | sim_jointmode_passive =0
562 | sim_jointmode_motion =1
563 | sim_jointmode_ik =2
564 | sim_jointmode_ikdependent =3
565 | sim_jointmode_dependent =4
566 | sim_jointmode_force =5
567 |
568 |
569 | # Navigation and selection modes with the mouse. Lower byte values are mutually exclusive upper byte bits can be combined
570 | sim_navigation_passive =0x0000
571 | sim_navigation_camerashift =0x0001
572 | sim_navigation_camerarotate =0x0002
573 | sim_navigation_camerazoom =0x0003
574 | sim_navigation_cameratilt =0x0004
575 | sim_navigation_cameraangle =0x0005
576 | sim_navigation_camerafly =0x0006
577 | sim_navigation_objectshift =0x0007
578 | sim_navigation_objectrotate =0x0008
579 | sim_navigation_reserved2 =0x0009
580 | sim_navigation_reserved3 =0x000A
581 | sim_navigation_jointpathtest =0x000B
582 | sim_navigation_ikmanip =0x000C
583 | sim_navigation_objectmultipleselection =0x000D
584 | # Bit-combine following values and add them to one of above's values for a valid navigation mode
585 | sim_navigation_reserved4 =0x0100
586 | sim_navigation_clickselection =0x0200
587 | sim_navigation_ctrlselection =0x0400
588 | sim_navigation_shiftselection =0x0800
589 | sim_navigation_camerazoomwheel =0x1000
590 | sim_navigation_camerarotaterightbutton =0x2000
591 |
592 |
593 |
594 | #Remote API constants
595 | SIMX_VERSION =0
596 | # Remote API message header structure
597 | SIMX_HEADER_SIZE =18
598 | simx_headeroffset_crc =0 # 1 simxUShort. Generated by the client or server. The CRC for the message
599 | simx_headeroffset_version =2 # 1 byte. Generated by the client or server. The version of the remote API software
600 | simx_headeroffset_message_id =3 # 1 simxInt. Generated by the client (and used in a reply by the server)
601 | simx_headeroffset_client_time =7 # 1 simxInt. Client time stamp generated by the client (and sent back by the server)
602 | simx_headeroffset_server_time =11 # 1 simxInt. Generated by the server when a reply is generated. The server timestamp
603 | simx_headeroffset_scene_id =15 # 1 simxUShort. Generated by the server. A unique ID identifying the scene currently displayed
604 | simx_headeroffset_server_state =17 # 1 byte. Generated by the server. Bit coded 0 set --> simulation not stopped 1 set --> simulation paused 2 set --> real-time switch on 3-5 edit mode type (0=no edit mode 1=triangle 2=vertex 3=edge 4=path 5=UI)
605 |
606 | # Remote API command header
607 | SIMX_SUBHEADER_SIZE =26
608 | simx_cmdheaderoffset_mem_size =0 # 1 simxInt. Generated by the client or server. The buffer size of the command.
609 | simx_cmdheaderoffset_full_mem_size =4 # 1 simxInt. Generated by the client or server. The full buffer size of the command (applies to split chunks).
610 | simx_cmdheaderoffset_pdata_offset0 =8 # 1 simxUShort. Generated by the client or server. The amount of data that is part of the command identification.
611 | simx_cmdheaderoffset_pdata_offset1 =10 # 1 simxInt. Generated by the client or server. The amount of shift of the pure data buffer (applies to split chunks).
612 | simx_cmdheaderoffset_cmd=14 # 1 simxInt. Generated by the client (and used in a reply by the server). The command combined with the operation mode of the command.
613 | simx_cmdheaderoffset_delay_or_split =18 # 1 simxUShort. Generated by the client or server. The amount of delay in ms of a continuous command or the max. pure data size to send at once (applies to split commands).
614 | simx_cmdheaderoffset_sim_time =20 # 1 simxInt. Generated by the server. The simulation time (in ms) when the command was executed (or 0 if simulation is not running)
615 | simx_cmdheaderoffset_status =24 # 1 byte. Generated by the server. (1 bit 0 is set --> error in function execution on server side). The client writes bit 1 if command cannot be overwritten
616 | simx_cmdheaderoffset_reserved =25 # 1 byte. Not yet used
617 |
618 |
619 |
620 |
621 |
622 | # Regular operation modes
623 | simx_opmode_oneshot =0x000000 # sends command as one chunk. Reply will also come as one chunk. Doesn't wait for the reply.
624 | simx_opmode_oneshot_wait =0x010000 # sends command as one chunk. Reply will also come as one chunk. Waits for the reply (_REPLY_WAIT_TIMEOUT_IN_MS is the timeout).
625 | simx_opmode_continuous =0x020000
626 | simx_opmode_streaming =0x020000 # sends command as one chunk. Command will be stored on the server and always executed
627 | #(every x ms (as far as possible) where x can be 0-65535. just add x to opmode_continuous).
628 | # A reply will be sent continuously each time as one chunk. Doesn't wait for the reply.
629 |
630 | # Operation modes for heavy data
631 | simx_opmode_oneshot_split =0x030000 # sends command as several chunks (max chunk size is x bytes where x can be _MIN_SPLIT_AMOUNT_IN_BYTES-65535. Just add x to opmode_oneshot_split). Reply will also come as several chunks. Doesn't wait for the reply.
632 | simx_opmode_continuous_split =0x040000
633 | simx_opmode_streaming_split =0x040000 # sends command as several chunks (max chunk size is x bytes where x can be _MIN_SPLIT_AMOUNT_IN_BYTES-65535. Just add x to opmode_continuous_split). Command will be stored on the server and always executed. A reply will be sent continuously each time as several chunks. Doesn't wait for the reply.
634 |
635 | # Special operation modes
636 | simx_opmode_discontinue =0x050000 # removes and cancels all commands stored on the client or server side (also continuous commands)
637 | simx_opmode_buffer =0x060000 # doesn't send anything but checks if a reply for the given command is available in the input buffer (i.e. previously received from the server)
638 | simx_opmode_remove =0x070000 # doesn't send anything and doesn't return any specific value. It just erases a similar command reply in the inbox (to free some memory)
639 |
640 |
641 | # Command return codes
642 | simx_return_ok =0x000000
643 | simx_return_novalue_flag =0x000001 # input buffer doesn't contain the specified command
644 | simx_return_timeout_flag =0x000002 # command reply not received in time for opmode_oneshot_wait operation mode
645 | simx_return_illegal_opmode_flag =0x000004 # command doesn't support the specified operation mode
646 | simx_return_remote_error_flag =0x000008 # command caused an error on the server side
647 | simx_return_split_progress_flag =0x000010 # previous similar command not yet fully processed (applies to opmode_oneshot_split operation modes)
648 | simx_return_local_error_flag =0x000020 # command caused an error on the client side
649 | simx_return_initialize_error_flag =0x000040 # simxStart was not yet called
650 |
651 | # Following for backward compatibility (same as above)
652 | simx_error_noerror =0x000000
653 | simx_error_novalue_flag =0x000001 # input buffer doesn't contain the specified command
654 | simx_error_timeout_flag =0x000002 # command reply not received in time for opmode_oneshot_wait operation mode
655 | simx_error_illegal_opmode_flag =0x000004 # command doesn't support the specified operation mode
656 | simx_error_remote_error_flag =0x000008 # command caused an error on the server side
657 | simx_error_split_progress_flag =0x000010 # previous similar command not yet fully processed (applies to opmode_oneshot_split operation modes)
658 | simx_error_local_error_flag =0x000020 # command caused an error on the client side
659 | simx_error_initialize_error_flag =0x000040 # simxStart was not yet called
660 |
661 |
662 |
--------------------------------------------------------------------------------
/PythonWorkspace/vrep.py:
--------------------------------------------------------------------------------
1 | # This file is part of the REMOTE API
2 | #
3 | # Copyright 2006-2015 Coppelia Robotics GmbH. All rights reserved.
4 | # marc@coppeliarobotics.com
5 | # www.coppeliarobotics.com
6 | #
7 | # The REMOTE API is licensed under the terms of GNU GPL:
8 | #
9 | # -------------------------------------------------------------------
10 | # The REMOTE API is free software: you can redistribute it and/or modify
11 | # it under the terms of the GNU General Public License as published by
12 | # the Free Software Foundation, either version 3 of the License, or
13 | # (at your option) any later version.
14 | #
15 | # THE REMOTE API IS DISTRIBUTED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
16 | # WARRANTY. THE USER WILL USE IT AT HIS/HER OWN RISK. THE ORIGINAL
17 | # AUTHORS AND COPPELIA ROBOTICS GMBH WILL NOT BE LIABLE FOR DATA LOSS,
18 | # DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR
19 | # MISUSING THIS SOFTWARE.
20 | #
21 | # See the GNU General Public License for more details.
22 | #
23 | # You should have received a copy of the GNU General Public License
24 | # along with the REMOTE API. If not, see .
25 | # -------------------------------------------------------------------
26 | #
27 | # This file was automatically created for V-REP release V3.2.3 rev4 on December 21st 2015
28 |
29 | import platform
30 | import struct
31 | import sys
32 | import ctypes as ct
33 | from vrepConst import *
34 |
35 | #load library
36 | libsimx = None
37 | try:
38 | if platform.system() =='cli':
39 | libsimx = ct.CDLL("./remoteApi.dll")
40 | elif platform.system() =='Windows':
41 | libsimx = ct.CDLL("./remoteApi.dll")
42 | elif platform.system() == 'Darwin':
43 | libsimx = ct.CDLL("./remoteApi.dylib")
44 | else:
45 | libsimx = ct.CDLL("./remoteApi.so")
46 | except:
47 | print ('----------------------------------------------------')
48 | print ('The remoteApi library could not be loaded. Make sure')
49 | print ('it is located in the same folder as "vrep.py", or')
50 | print ('appropriately adjust the file "vrep.py"')
51 | print ('----------------------------------------------------')
52 | print ('')
53 |
54 | #ctypes wrapper prototypes
55 | c_GetJointPosition = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetJointPosition", libsimx))
56 | c_SetJointPosition = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_float, ct.c_int32)(("simxSetJointPosition", libsimx))
57 | c_GetJointMatrix = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetJointMatrix", libsimx))
58 | c_SetSphericalJointMatrix = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxSetSphericalJointMatrix", libsimx))
59 | c_SetJointTargetVelocity = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_float, ct.c_int32)(("simxSetJointTargetVelocity", libsimx))
60 | c_SetJointTargetPosition = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_float, ct.c_int32)(("simxSetJointTargetPosition", libsimx))
61 | c_GetJointForce = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetJointForce", libsimx))
62 | c_SetJointForce = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_float, ct.c_int32)(("simxSetJointForce", libsimx))
63 | c_ReadForceSensor = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_ubyte), ct.POINTER(ct.c_float), ct.POINTER(ct.c_float), ct.c_int32)(("simxReadForceSensor", libsimx))
64 | c_BreakForceSensor = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32)(("simxBreakForceSensor", libsimx))
65 | c_ReadVisionSensor = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_ubyte), ct.POINTER(ct.POINTER(ct.c_float)), ct.POINTER(ct.POINTER(ct.c_int32)), ct.c_int32)(("simxReadVisionSensor", libsimx))
66 | c_GetObjectHandle = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetObjectHandle", libsimx))
67 | c_GetVisionSensorImage = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_byte)), ct.c_ubyte, ct.c_int32)(("simxGetVisionSensorImage", libsimx))
68 | c_SetVisionSensorImage = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_byte), ct.c_int32, ct.c_ubyte, ct.c_int32)(("simxSetVisionSensorImage", libsimx))
69 | c_GetVisionSensorDepthBuffer= ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_float)), ct.c_int32)(("simxGetVisionSensorDepthBuffer", libsimx))
70 | c_GetObjectChild = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetObjectChild", libsimx))
71 | c_GetObjectParent = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetObjectParent", libsimx))
72 | c_ReadProximitySensor = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_ubyte), ct.POINTER(ct.c_float), ct.POINTER(ct.c_int32), ct.POINTER(ct.c_float), ct.c_int32)(("simxReadProximitySensor", libsimx))
73 | c_LoadModel = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_ubyte, ct.POINTER(ct.c_int32), ct.c_int32)(("simxLoadModel", libsimx))
74 | c_LoadUI = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_ubyte, ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_int32)), ct.c_int32)(("simxLoadUI", libsimx))
75 | c_LoadScene = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_ubyte, ct.c_int32)(("simxLoadScene", libsimx))
76 | c_StartSimulation = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32)(("simxStartSimulation", libsimx))
77 | c_PauseSimulation = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32)(("simxPauseSimulation", libsimx))
78 | c_StopSimulation = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32)(("simxStopSimulation", libsimx))
79 | c_GetUIHandle = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetUIHandle", libsimx))
80 | c_GetUISlider = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetUISlider", libsimx))
81 | c_SetUISlider = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32)(("simxSetUISlider", libsimx))
82 | c_GetUIEventButton = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetUIEventButton", libsimx))
83 | c_GetUIButtonProperty = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetUIButtonProperty", libsimx))
84 | c_SetUIButtonProperty = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32)(("simxSetUIButtonProperty", libsimx))
85 | c_AddStatusbarMessage = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32)(("simxAddStatusbarMessage", libsimx))
86 | c_AuxiliaryConsoleOpen = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.POINTER(ct.c_int32), ct.POINTER(ct.c_float), ct.POINTER(ct.c_float), ct.POINTER(ct.c_int32), ct.c_int32)(("simxAuxiliaryConsoleOpen", libsimx))
87 | c_AuxiliaryConsoleClose = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32)(("simxAuxiliaryConsoleClose", libsimx))
88 | c_AuxiliaryConsolePrint = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32)(("simxAuxiliaryConsolePrint", libsimx))
89 | c_AuxiliaryConsoleShow = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_ubyte, ct.c_int32)(("simxAuxiliaryConsoleShow", libsimx))
90 | c_GetObjectOrientation = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetObjectOrientation", libsimx))
91 | c_GetObjectPosition = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetObjectPosition", libsimx))
92 | c_SetObjectOrientation = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxSetObjectOrientation", libsimx))
93 | c_SetObjectPosition = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxSetObjectPosition", libsimx))
94 | c_SetObjectParent = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.c_ubyte, ct.c_int32)(("simxSetObjectParent", libsimx))
95 | c_SetUIButtonLabel = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_char), ct.c_int32)(("simxSetUIButtonLabel", libsimx))
96 | c_GetLastErrors = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_char)), ct.c_int32)(("simxGetLastErrors", libsimx))
97 | c_GetArrayParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetArrayParameter", libsimx))
98 | c_SetArrayParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxSetArrayParameter", libsimx))
99 | c_GetBooleanParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_ubyte), ct.c_int32)(("simxGetBooleanParameter", libsimx))
100 | c_SetBooleanParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_ubyte, ct.c_int32)(("simxSetBooleanParameter", libsimx))
101 | c_GetIntegerParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetIntegerParameter", libsimx))
102 | c_SetIntegerParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32)(("simxSetIntegerParameter", libsimx))
103 | c_GetFloatingParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetFloatingParameter", libsimx))
104 | c_SetFloatingParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_float, ct.c_int32)(("simxSetFloatingParameter", libsimx))
105 | c_GetStringParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.POINTER(ct.c_char)), ct.c_int32)(("simxGetStringParameter", libsimx))
106 | c_GetCollisionHandle = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetCollisionHandle", libsimx))
107 | c_GetDistanceHandle = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetDistanceHandle", libsimx))
108 | # c_GetCollectionHandle = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetCollectionHandle", libsimx))
109 | c_ReadCollision = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_ubyte), ct.c_int32)(("simxReadCollision", libsimx))
110 | c_ReadDistance = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxReadDistance", libsimx))
111 | c_RemoveObject = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32)(("simxRemoveObject", libsimx))
112 | c_RemoveModel = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32)(("simxRemoveModel", libsimx))
113 | c_RemoveUI = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32)(("simxRemoveUI", libsimx))
114 | c_CloseScene = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32)(("simxCloseScene", libsimx))
115 | c_GetObjects = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_int32)), ct.c_int32)(("simxGetObjects", libsimx))
116 | c_DisplayDialog = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_char), ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_float), ct.POINTER(ct.c_float), ct.POINTER(ct.c_int32), ct.POINTER(ct.c_int32), ct.c_int32)(("simxDisplayDialog", libsimx))
117 | c_EndDialog = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32)(("simxEndDialog", libsimx))
118 | c_GetDialogInput = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.POINTER(ct.c_char)), ct.c_int32)(("simxGetDialogInput", libsimx))
119 | c_GetDialogResult = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetDialogResult", libsimx))
120 | c_CopyPasteObjects = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32, ct.POINTER(ct.POINTER(ct.c_int32)), ct.POINTER(ct.c_int32), ct.c_int32)(("simxCopyPasteObjects", libsimx))
121 | c_GetObjectSelection = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.POINTER(ct.c_int32)), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetObjectSelection", libsimx))
122 | c_SetObjectSelection = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32, ct.c_int32)(("simxSetObjectSelection", libsimx))
123 | c_ClearFloatSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32)(("simxClearFloatSignal", libsimx))
124 | c_ClearIntegerSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32)(("simxClearIntegerSignal", libsimx))
125 | c_ClearStringSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32)(("simxClearStringSignal", libsimx))
126 | c_GetFloatSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_float), ct.c_int32)(("simxGetFloatSignal", libsimx))
127 | c_GetIntegerSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetIntegerSignal", libsimx))
128 | c_GetStringSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.POINTER(ct.c_ubyte)), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetStringSignal", libsimx))
129 | c_SetFloatSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_float, ct.c_int32)(("simxSetFloatSignal", libsimx))
130 | c_SetIntegerSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32, ct.c_int32)(("simxSetIntegerSignal", libsimx))
131 | c_SetStringSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_ubyte), ct.c_int32, ct.c_int32)(("simxSetStringSignal", libsimx))
132 | c_AppendStringSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_ubyte), ct.c_int32, ct.c_int32)(("simxAppendStringSignal", libsimx))
133 | c_WriteStringStream = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_ubyte), ct.c_int32, ct.c_int32)(("simxWriteStringStream", libsimx))
134 | c_GetObjectFloatParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.c_int32)(("simxGetObjectFloatParameter", libsimx))
135 | c_SetObjectFloatParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.c_float, ct.c_int32)(("simxSetObjectFloatParameter", libsimx))
136 | c_GetObjectIntParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetObjectIntParameter", libsimx))
137 | c_SetObjectIntParameter = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32)(("simxSetObjectIntParameter", libsimx))
138 | c_GetModelProperty = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetModelProperty", libsimx))
139 | c_SetModelProperty = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.c_int32)(("simxSetModelProperty", libsimx))
140 | c_Start = ct.CFUNCTYPE(ct.c_int32,ct.POINTER(ct.c_char), ct.c_int32, ct.c_ubyte, ct.c_ubyte, ct.c_int32, ct.c_int32)(("simxStart", libsimx))
141 | c_Finish = ct.CFUNCTYPE(None, ct.c_int32)(("simxFinish", libsimx))
142 | c_GetPingTime = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_int32))(("simxGetPingTime", libsimx))
143 | c_GetLastCmdTime = ct.CFUNCTYPE(ct.c_int32,ct.c_int32)(("simxGetLastCmdTime", libsimx))
144 | c_SynchronousTrigger = ct.CFUNCTYPE(ct.c_int32,ct.c_int32)(("simxSynchronousTrigger", libsimx))
145 | c_Synchronous = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_ubyte)(("simxSynchronous", libsimx))
146 | c_PauseCommunication = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_ubyte)(("simxPauseCommunication", libsimx))
147 | c_GetInMessageInfo = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32))(("simxGetInMessageInfo", libsimx))
148 | c_GetOutMessageInfo = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32))(("simxGetOutMessageInfo", libsimx))
149 | c_GetConnectionId = ct.CFUNCTYPE(ct.c_int32,ct.c_int32)(("simxGetConnectionId", libsimx))
150 | c_CreateBuffer = ct.CFUNCTYPE(ct.POINTER(ct.c_ubyte), ct.c_int32)(("simxCreateBuffer", libsimx))
151 | c_ReleaseBuffer = ct.CFUNCTYPE(None, ct.c_void_p)(("simxReleaseBuffer", libsimx))
152 | c_TransferFile = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_char), ct.c_int32, ct.c_int32)(("simxTransferFile", libsimx))
153 | c_EraseFile = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.c_int32)(("simxEraseFile", libsimx))
154 | c_GetAndClearStringSignal = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.POINTER(ct.c_ubyte)), ct.POINTER(ct.c_int32), ct.c_int32)(("simxGetAndClearStringSignal", libsimx))
155 | c_ReadStringStream = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.POINTER(ct.c_ubyte)), ct.POINTER(ct.c_int32), ct.c_int32)(("simxReadStringStream", libsimx))
156 | c_CreateDummy = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_float, ct.POINTER(ct.c_ubyte), ct.POINTER(ct.c_int32), ct.c_int32)(("simxCreateDummy", libsimx))
157 | c_Query = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.c_ubyte), ct.c_int32, ct.POINTER(ct.c_char), ct.POINTER(ct.POINTER(ct.c_ubyte)), ct.POINTER(ct.c_int32), ct.c_int32)(("simxQuery", libsimx))
158 | c_GetObjectGroupData = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.c_int32, ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_int32)), ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_int32)), ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_float)), ct.POINTER(ct.c_int32), ct.POINTER(ct.POINTER(ct.c_char)), ct.c_int32)(("simxGetObjectGroupData", libsimx))
159 | c_GetObjectVelocity = ct.CFUNCTYPE(ct.c_int32,ct.c_int32, ct.c_int32, ct.POINTER(ct.c_float), ct.POINTER(ct.c_float), ct.c_int32)(("simxGetObjectVelocity", libsimx))
160 |
161 | #API functions
162 | def simxGetJointPosition(clientID, jointHandle, operationMode):
163 | '''
164 | Please have a look at the function description/documentation in the V-REP user manual
165 | '''
166 | position = ct.c_float()
167 | return c_GetJointPosition(clientID, jointHandle, ct.byref(position), operationMode), position.value
168 |
169 | def simxSetJointPosition(clientID, jointHandle, position, operationMode):
170 | '''
171 | Please have a look at the function description/documentation in the V-REP user manual
172 | '''
173 |
174 | return c_SetJointPosition(clientID, jointHandle, position, operationMode)
175 |
176 | def simxGetJointMatrix(clientID, jointHandle, operationMode):
177 | '''
178 | Please have a look at the function description/documentation in the V-REP user manual
179 | '''
180 | matrix = (ct.c_float*12)()
181 | ret = c_GetJointMatrix(clientID, jointHandle, matrix, operationMode)
182 | arr = []
183 | for i in range(12):
184 | arr.append(matrix[i])
185 | return ret, arr
186 |
187 | def simxSetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode):
188 | '''
189 | Please have a look at the function description/documentation in the V-REP user manual
190 | '''
191 | matrix = (ct.c_float*12)(*matrix)
192 | return c_SetSphericalJointMatrix(clientID, jointHandle, matrix, operationMode)
193 |
194 | def simxSetJointTargetVelocity(clientID, jointHandle, targetVelocity, operationMode):
195 | '''
196 | Please have a look at the function description/documentation in the V-REP user manual
197 | '''
198 |
199 | return c_SetJointTargetVelocity(clientID, jointHandle, targetVelocity, operationMode)
200 |
201 | def simxSetJointTargetPosition(clientID, jointHandle, targetPosition, operationMode):
202 | '''
203 | Please have a look at the function description/documentation in the V-REP user manual
204 | '''
205 |
206 | return c_SetJointTargetPosition(clientID, jointHandle, targetPosition, operationMode)
207 |
208 | def simxJointGetForce(clientID, jointHandle, operationMode):
209 | '''
210 | Please have a look at the function description/documentation in the V-REP user manual
211 | '''
212 | force = ct.c_float()
213 | return c_GetJointForce(clientID, jointHandle, ct.byref(force), operationMode), force.value
214 |
215 | def simxGetJointForce(clientID, jointHandle, operationMode):
216 | '''
217 | Please have a look at the function description/documentation in the V-REP user manual
218 | '''
219 | force = ct.c_float()
220 | return c_GetJointForce(clientID, jointHandle, ct.byref(force), operationMode), force.value
221 |
222 | def simxSetJointForce(clientID, jointHandle, force, operationMode):
223 | '''
224 | Please have a look at the function description/documentation in the V-REP user manual
225 | '''
226 | return c_SetJointForce(clientID, jointHandle, force, operationMode)
227 |
228 | def simxReadForceSensor(clientID, forceSensorHandle, operationMode):
229 | '''
230 | Please have a look at the function description/documentation in the V-REP user manual
231 | '''
232 | state = ct.c_ubyte()
233 | forceVector = (ct.c_float*3)()
234 | torqueVector = (ct.c_float*3)()
235 | ret = c_ReadForceSensor(clientID, forceSensorHandle, ct.byref(state), forceVector, torqueVector, operationMode)
236 | arr1 = []
237 | for i in range(3):
238 | arr1.append(forceVector[i])
239 | arr2 = []
240 | for i in range(3):
241 | arr2.append(torqueVector[i])
242 | if sys.version_info[0] == 3:
243 | state=state.value
244 | else:
245 | state=state.value
246 | return ret, state, arr1, arr2
247 |
248 | def simxBreakForceSensor(clientID, forceSensorHandle, operationMode):
249 | '''
250 | Please have a look at the function description/documentation in the V-REP user manual
251 | '''
252 | return c_BreakForceSensor(clientID, forceSensorHandle, operationMode)
253 |
254 | def simxReadVisionSensor(clientID, sensorHandle, operationMode):
255 | '''
256 | Please have a look at the function description/documentation in the V-REP user manual
257 | '''
258 |
259 | detectionState = ct.c_ubyte()
260 | auxValues = ct.POINTER(ct.c_float)()
261 | auxValuesCount = ct.POINTER(ct.c_int)()
262 | ret = c_ReadVisionSensor(clientID, sensorHandle, ct.byref(detectionState), ct.byref(auxValues), ct.byref(auxValuesCount), operationMode)
263 |
264 | auxValues2 = []
265 | if ret == 0:
266 | s = 0
267 | for i in range(auxValuesCount[0]):
268 | auxValues2.append(auxValues[s:s+auxValuesCount[i+1]])
269 | s += auxValuesCount[i+1]
270 |
271 | #free C buffers
272 | c_ReleaseBuffer(auxValues)
273 | c_ReleaseBuffer(auxValuesCount)
274 |
275 | return ret, bool(detectionState.value!=0), auxValues2
276 |
277 | def simxGetObjectHandle(clientID, objectName, operationMode):
278 | '''
279 | Please have a look at the function description/documentation in the V-REP user manual
280 | '''
281 | handle = ct.c_int()
282 | if (sys.version_info[0] == 3) and (type(objectName) is str):
283 | objectName=objectName.encode('utf-8')
284 | return c_GetObjectHandle(clientID, objectName, ct.byref(handle), operationMode), handle.value
285 |
286 | def simxGetVisionSensorImage(clientID, sensorHandle, options, operationMode):
287 | '''
288 | Please have a look at the function description/documentation in the V-REP user manual
289 | '''
290 |
291 | resolution = (ct.c_int*2)()
292 | c_image = ct.POINTER(ct.c_byte)()
293 | bytesPerPixel = 3
294 | if (options and 1) != 0:
295 | bytesPerPixel = 1
296 | ret = c_GetVisionSensorImage(clientID, sensorHandle, resolution, ct.byref(c_image), options, operationMode)
297 |
298 | reso = []
299 | image = []
300 | if (ret == 0):
301 | image = [None]*resolution[0]*resolution[1]*bytesPerPixel
302 | for i in range(resolution[0] * resolution[1] * bytesPerPixel):
303 | image[i] = c_image[i]
304 | for i in range(2):
305 | reso.append(resolution[i])
306 | return ret, reso, image
307 |
308 | def simxSetVisionSensorImage(clientID, sensorHandle, image, options, operationMode):
309 | '''
310 | Please have a look at the function description/documentation in the V-REP user manual
311 | '''
312 | size = len(image)
313 | image_bytes = (ct.c_byte*size)(*image)
314 | return c_SetVisionSensorImage(clientID, sensorHandle, image_bytes, size, options, operationMode)
315 |
316 | def simxGetVisionSensorDepthBuffer(clientID, sensorHandle, operationMode):
317 | '''
318 | Please have a look at the function description/documentation in the V-REP user manual
319 | '''
320 | c_buffer = ct.POINTER(ct.c_float)()
321 | resolution = (ct.c_int*2)()
322 | ret = c_GetVisionSensorDepthBuffer(clientID, sensorHandle, resolution, ct.byref(c_buffer), operationMode)
323 | reso = []
324 | buffer = []
325 | if (ret == 0):
326 | buffer = [None]*resolution[0]*resolution[1]
327 | for i in range(resolution[0] * resolution[1]):
328 | buffer[i] = c_buffer[i]
329 | for i in range(2):
330 | reso.append(resolution[i])
331 | return ret, reso, buffer
332 |
333 | def simxGetObjectChild(clientID, parentObjectHandle, childIndex, operationMode):
334 | '''
335 | Please have a look at the function description/documentation in the V-REP user manual
336 | '''
337 | childObjectHandle = ct.c_int()
338 | return c_GetObjectChild(clientID, parentObjectHandle, childIndex, ct.byref(childObjectHandle), operationMode), childObjectHandle.value
339 |
340 | def simxGetObjectParent(clientID, childObjectHandle, operationMode):
341 | '''
342 | Please have a look at the function description/documentation in the V-REP user manual
343 | '''
344 |
345 | parentObjectHandle = ct.c_int()
346 | return c_GetObjectParent(clientID, childObjectHandle, ct.byref(parentObjectHandle), operationMode), parentObjectHandle.value
347 |
348 | def simxReadProximitySensor(clientID, sensorHandle, operationMode):
349 | '''
350 | Please have a look at the function description/documentation in the V-REP user manual
351 | '''
352 |
353 | detectionState = ct.c_ubyte()
354 | detectedObjectHandle = ct.c_int()
355 | detectedPoint = (ct.c_float*3)()
356 | detectedSurfaceNormalVector = (ct.c_float*3)()
357 | ret = c_ReadProximitySensor(clientID, sensorHandle, ct.byref(detectionState), detectedPoint, ct.byref(detectedObjectHandle), detectedSurfaceNormalVector, operationMode)
358 | arr1 = []
359 | for i in range(3):
360 | arr1.append(detectedPoint[i])
361 | arr2 = []
362 | for i in range(3):
363 | arr2.append(detectedSurfaceNormalVector[i])
364 | return ret, bool(detectionState.value!=0), arr1, detectedObjectHandle.value, arr2
365 |
366 | def simxLoadModel(clientID, modelPathAndName, options, operationMode):
367 | '''
368 | Please have a look at the function description/documentation in the V-REP user manual
369 | '''
370 | baseHandle = ct.c_int()
371 | if (sys.version_info[0] == 3) and (type(modelPathAndName) is str):
372 | modelPathAndName=modelPathAndName.encode('utf-8')
373 | return c_LoadModel(clientID, modelPathAndName, options, ct.byref(baseHandle), operationMode), baseHandle.value
374 |
375 | def simxLoadUI(clientID, uiPathAndName, options, operationMode):
376 | '''
377 | Please have a look at the function description/documentation in the V-REP user manual
378 | '''
379 |
380 | count = ct.c_int()
381 | uiHandles = ct.POINTER(ct.c_int)()
382 | if (sys.version_info[0] == 3) and (type(uiPathAndName) is str):
383 | uiPathAndName=uiPathAndName.encode('utf-8')
384 | ret = c_LoadUI(clientID, uiPathAndName, options, ct.byref(count), ct.byref(uiHandles), operationMode)
385 |
386 | handles = []
387 | if ret == 0:
388 | for i in range(count.value):
389 | handles.append(uiHandles[i])
390 | #free C buffers
391 | c_ReleaseBuffer(uiHandles)
392 |
393 | return ret, handles
394 |
395 | def simxLoadScene(clientID, scenePathAndName, options, operationMode):
396 | '''
397 | Please have a look at the function description/documentation in the V-REP user manual
398 | '''
399 |
400 | if (sys.version_info[0] == 3) and (type(scenePathAndName) is str):
401 | scenePathAndName=scenePathAndName.encode('utf-8')
402 | return c_LoadScene(clientID, scenePathAndName, options, operationMode)
403 |
404 | def simxStartSimulation(clientID, operationMode):
405 | '''
406 | Please have a look at the function description/documentation in the V-REP user manual
407 | '''
408 |
409 | return c_StartSimulation(clientID, operationMode)
410 |
411 | def simxPauseSimulation(clientID, operationMode):
412 | '''
413 | Please have a look at the function description/documentation in the V-REP user manual
414 | '''
415 |
416 | return c_PauseSimulation(clientID, operationMode)
417 |
418 | def simxStopSimulation(clientID, operationMode):
419 | '''
420 | Please have a look at the function description/documentation in the V-REP user manual
421 | '''
422 |
423 | return c_StopSimulation(clientID, operationMode)
424 |
425 | def simxGetUIHandle(clientID, uiName, operationMode):
426 | '''
427 | Please have a look at the function description/documentation in the V-REP user manual
428 | '''
429 |
430 | handle = ct.c_int()
431 | if (sys.version_info[0] == 3) and (type(uiName) is str):
432 | uiName=uiName.encode('utf-8')
433 | return c_GetUIHandle(clientID, uiName, ct.byref(handle), operationMode), handle.value
434 |
435 | def simxGetUISlider(clientID, uiHandle, uiButtonID, operationMode):
436 | '''
437 | Please have a look at the function description/documentation in the V-REP user manual
438 | '''
439 |
440 | position = ct.c_int()
441 | return c_GetUISlider(clientID, uiHandle, uiButtonID, ct.byref(position), operationMode), position.value
442 |
443 | def simxSetUISlider(clientID, uiHandle, uiButtonID, position, operationMode):
444 | '''
445 | Please have a look at the function description/documentation in the V-REP user manual
446 | '''
447 |
448 | return c_SetUISlider(clientID, uiHandle, uiButtonID, position, operationMode)
449 |
450 | def simxGetUIEventButton(clientID, uiHandle, operationMode):
451 | '''
452 | Please have a look at the function description/documentation in the V-REP user manual
453 | '''
454 |
455 | uiEventButtonID = ct.c_int()
456 | auxValues = (ct.c_int*2)()
457 | ret = c_GetUIEventButton(clientID, uiHandle, ct.byref(uiEventButtonID), auxValues, operationMode)
458 | arr = []
459 | for i in range(2):
460 | arr.append(auxValues[i])
461 | return ret, uiEventButtonID.value, arr
462 |
463 | def simxGetUIButtonProperty(clientID, uiHandle, uiButtonID, operationMode):
464 | '''
465 | Please have a look at the function description/documentation in the V-REP user manual
466 | '''
467 |
468 | prop = ct.c_int()
469 | return c_GetUIButtonProperty(clientID, uiHandle, uiButtonID, ct.byref(prop), operationMode), prop.value
470 |
471 | def simxSetUIButtonProperty(clientID, uiHandle, uiButtonID, prop, operationMode):
472 | '''
473 | Please have a look at the function description/documentation in the V-REP user manual
474 | '''
475 |
476 | return c_SetUIButtonProperty(clientID, uiHandle, uiButtonID, prop, operationMode)
477 |
478 | def simxAddStatusbarMessage(clientID, message, operationMode):
479 | '''
480 | Please have a look at the function description/documentation in the V-REP user manual
481 | '''
482 |
483 | if (sys.version_info[0] == 3) and (type(message) is str):
484 | message=message.encode('utf-8')
485 | return c_AddStatusbarMessage(clientID, message, operationMode)
486 |
487 | def simxAuxiliaryConsoleOpen(clientID, title, maxLines, mode, position, size, textColor, backgroundColor, operationMode):
488 | '''
489 | Please have a look at the function description/documentation in the V-REP user manual
490 | '''
491 |
492 | consoleHandle = ct.c_int()
493 | if (sys.version_info[0] == 3) and (type(title) is str):
494 | title=title.encode('utf-8')
495 | if position != None:
496 | c_position = (ct.c_int*2)(*position)
497 | else:
498 | c_position = None
499 | if size != None:
500 | c_size = (ct.c_int*2)(*size)
501 | else:
502 | c_size = None
503 | if textColor != None:
504 | c_textColor = (ct.c_float*3)(*textColor)
505 | else:
506 | c_textColor = None
507 | if backgroundColor != None:
508 | c_backgroundColor = (ct.c_float*3)(*backgroundColor)
509 | else:
510 | c_backgroundColor = None
511 | return c_AuxiliaryConsoleOpen(clientID, title, maxLines, mode, c_position, c_size, c_textColor, c_backgroundColor, ct.byref(consoleHandle), operationMode), consoleHandle.value
512 |
513 | def simxAuxiliaryConsoleClose(clientID, consoleHandle, operationMode):
514 | '''
515 | Please have a look at the function description/documentation in the V-REP user manual
516 | '''
517 |
518 | return c_AuxiliaryConsoleClose(clientID, consoleHandle, operationMode)
519 |
520 | def simxAuxiliaryConsolePrint(clientID, consoleHandle, txt, operationMode):
521 | '''
522 | Please have a look at the function description/documentation in the V-REP user manual
523 | '''
524 |
525 | if (sys.version_info[0] == 3) and (type(txt) is str):
526 | txt=txt.encode('utf-8')
527 | return c_AuxiliaryConsolePrint(clientID, consoleHandle, txt, operationMode)
528 |
529 | def simxAuxiliaryConsoleShow(clientID, consoleHandle, showState, operationMode):
530 | '''
531 | Please have a look at the function description/documentation in the V-REP user manual
532 | '''
533 |
534 | return c_AuxiliaryConsoleShow(clientID, consoleHandle, showState, operationMode)
535 |
536 | def simxGetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, operationMode):
537 | '''
538 | Please have a look at the function description/documentation in the V-REP user manual
539 | '''
540 | eulerAngles = (ct.c_float*3)()
541 | ret = c_GetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, eulerAngles, operationMode)
542 | arr = []
543 | for i in range(3):
544 | arr.append(eulerAngles[i])
545 | return ret, arr
546 |
547 | def simxGetObjectPosition(clientID, objectHandle, relativeToObjectHandle, operationMode):
548 | '''
549 | Please have a look at the function description/documentation in the V-REP user manual
550 | '''
551 | position = (ct.c_float*3)()
552 | ret = c_GetObjectPosition(clientID, objectHandle, relativeToObjectHandle, position, operationMode)
553 | arr = []
554 | for i in range(3):
555 | arr.append(position[i])
556 | return ret, arr
557 |
558 | def simxSetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, eulerAngles, operationMode):
559 | '''
560 | Please have a look at the function description/documentation in the V-REP user manual
561 | '''
562 |
563 | angles = (ct.c_float*3)(*eulerAngles)
564 | return c_SetObjectOrientation(clientID, objectHandle, relativeToObjectHandle, angles, operationMode)
565 |
566 | def simxSetObjectPosition(clientID, objectHandle, relativeToObjectHandle, position, operationMode):
567 | '''
568 | Please have a look at the function description/documentation in the V-REP user manual
569 | '''
570 |
571 | c_position = (ct.c_float*3)(*position)
572 | return c_SetObjectPosition(clientID, objectHandle, relativeToObjectHandle, c_position, operationMode)
573 |
574 | def simxSetObjectParent(clientID, objectHandle, parentObject, keepInPlace, operationMode):
575 | '''
576 | Please have a look at the function description/documentation in the V-REP user manual
577 | '''
578 |
579 | return c_SetObjectParent(clientID, objectHandle, parentObject, keepInPlace, operationMode)
580 |
581 | def simxSetUIButtonLabel(clientID, uiHandle, uiButtonID, upStateLabel, downStateLabel, operationMode):
582 | '''
583 | Please have a look at the function description/documentation in the V-REP user manual
584 | '''
585 |
586 | if sys.version_info[0] == 3:
587 | if type(upStateLabel) is str:
588 | upStateLabel=upStateLabel.encode('utf-8')
589 | if type(downStateLabel) is str:
590 | downStateLabel=downStateLabel.encode('utf-8')
591 | return c_SetUIButtonLabel(clientID, uiHandle, uiButtonID, upStateLabel, downStateLabel, operationMode)
592 |
593 | def simxGetLastErrors(clientID, operationMode):
594 | '''
595 | Please have a look at the function description/documentation in the V-REP user manual
596 | '''
597 | errors =[]
598 | errorCnt = ct.c_int()
599 | errorStrings = ct.POINTER(ct.c_char)()
600 | ret = c_GetLastErrors(clientID, ct.byref(errorCnt), ct.byref(errorStrings), operationMode)
601 | if ret == 0:
602 | s = 0
603 | for i in range(errorCnt.value):
604 | a = bytearray()
605 | while errorStrings[s] != b'\0':
606 | if sys.version_info[0] == 3:
607 | a.append(int.from_bytes(errorStrings[s],'big'))
608 | else:
609 | a.append(errorStrings[s])
610 | s += 1
611 | s += 1 #skip null
612 | if sys.version_info[0] == 3:
613 | errors.append(str(a,'utf-8'))
614 | else:
615 | errors.append(str(a))
616 |
617 | return ret, errors
618 |
619 | def simxGetArrayParameter(clientID, paramIdentifier, operationMode):
620 | '''
621 | Please have a look at the function description/documentation in the V-REP user manual
622 | '''
623 | paramValues = (ct.c_float*3)()
624 | ret = c_GetArrayParameter(clientID, paramIdentifier, paramValues, operationMode)
625 | arr = []
626 | for i in range(3):
627 | arr.append(paramValues[i])
628 | return ret, arr
629 |
630 | def simxSetArrayParameter(clientID, paramIdentifier, paramValues, operationMode):
631 | '''
632 | Please have a look at the function description/documentation in the V-REP user manual
633 | '''
634 |
635 | c_paramValues = (ct.c_float*3)(*paramValues)
636 | return c_SetArrayParameter(clientID, paramIdentifier, c_paramValues, operationMode)
637 |
638 | def simxGetBooleanParameter(clientID, paramIdentifier, operationMode):
639 | '''
640 | Please have a look at the function description/documentation in the V-REP user manual
641 | '''
642 |
643 | paramValue = ct.c_ubyte()
644 | return c_GetBooleanParameter(clientID, paramIdentifier, ct.byref(paramValue), operationMode), bool(paramValue.value!=0)
645 |
646 | def simxSetBooleanParameter(clientID, paramIdentifier, paramValue, operationMode):
647 | '''
648 | Please have a look at the function description/documentation in the V-REP user manual
649 | '''
650 |
651 | return c_SetBooleanParameter(clientID, paramIdentifier, paramValue, operationMode)
652 |
653 | def simxGetIntegerParameter(clientID, paramIdentifier, operationMode):
654 | '''
655 | Please have a look at the function description/documentation in the V-REP user manual
656 | '''
657 |
658 | paramValue = ct.c_int()
659 | return c_GetIntegerParameter(clientID, paramIdentifier, ct.byref(paramValue), operationMode), paramValue.value
660 |
661 | def simxSetIntegerParameter(clientID, paramIdentifier, paramValue, operationMode):
662 | '''
663 | Please have a look at the function description/documentation in the V-REP user manual
664 | '''
665 |
666 | return c_SetIntegerParameter(clientID, paramIdentifier, paramValue, operationMode)
667 |
668 | def simxGetFloatingParameter(clientID, paramIdentifier, operationMode):
669 | '''
670 | Please have a look at the function description/documentation in the V-REP user manual
671 | '''
672 |
673 | paramValue = ct.c_float()
674 | return c_GetFloatingParameter(clientID, paramIdentifier, ct.byref(paramValue), operationMode), paramValue.value
675 |
676 | def simxSetFloatingParameter(clientID, paramIdentifier, paramValue, operationMode):
677 | '''
678 | Please have a look at the function description/documentation in the V-REP user manual
679 | '''
680 |
681 | return c_SetFloatingParameter(clientID, paramIdentifier, paramValue, operationMode)
682 |
683 | def simxGetStringParameter(clientID, paramIdentifier, operationMode):
684 | '''
685 | Please have a look at the function description/documentation in the V-REP user manual
686 | '''
687 | paramValue = ct.POINTER(ct.c_char)()
688 | ret = c_GetStringParameter(clientID, paramIdentifier, ct.byref(paramValue), operationMode)
689 |
690 | a = bytearray()
691 | if ret == 0:
692 | i = 0
693 | while paramValue[i] != b'\0':
694 | if sys.version_info[0] == 3:
695 | a.append(int.from_bytes(paramValue[i],'big'))
696 | else:
697 | a.append(paramValue[i])
698 | i=i+1
699 | if sys.version_info[0] == 3:
700 | a=str(a,'utf-8')
701 | else:
702 | a=str(a)
703 | return ret, a
704 |
705 | def simxGetCollisionHandle(clientID, collisionObjectName, operationMode):
706 | '''
707 | Please have a look at the function description/documentation in the V-REP user manual
708 | '''
709 |
710 | handle = ct.c_int()
711 | if (sys.version_info[0] == 3) and (type(collisionObjectName) is str):
712 | collisionObjectName=collisionObjectName.encode('utf-8')
713 | return c_GetCollisionHandle(clientID, collisionObjectName, ct.byref(handle), operationMode), handle.value
714 |
715 | def simxGetCollectionHandle(clientID, collectionName, operationMode):
716 | '''
717 | Please have a look at the function description/documentation in the V-REP user manual
718 | '''
719 |
720 | handle = ct.c_int()
721 | if (sys.version_info[0] == 3) and (type(collectionName) is str):
722 | collectionName=collectionName.encode('utf-8')
723 | return c_GetCollectionHandle(clientID, collectionName, ct.byref(handle), operationMode), handle.value
724 |
725 | def simxGetDistanceHandle(clientID, distanceObjectName, operationMode):
726 | '''
727 | Please have a look at the function description/documentation in the V-REP user manual
728 | '''
729 |
730 | handle = ct.c_int()
731 | if (sys.version_info[0] == 3) and (type(distanceObjectName) is str):
732 | distanceObjectName=distanceObjectName.encode('utf-8')
733 | return c_GetDistanceHandle(clientID, distanceObjectName, ct.byref(handle), operationMode), handle.value
734 |
735 | def simxReadCollision(clientID, collisionObjectHandle, operationMode):
736 | '''
737 | Please have a look at the function description/documentation in the V-REP user manual
738 | '''
739 | collisionState = ct.c_ubyte()
740 | return c_ReadCollision(clientID, collisionObjectHandle, ct.byref(collisionState), operationMode), bool(collisionState.value!=0)
741 |
742 | def simxReadDistance(clientID, distanceObjectHandle, operationMode):
743 | '''
744 | Please have a look at the function description/documentation in the V-REP user manual
745 | '''
746 |
747 | minimumDistance = ct.c_float()
748 | return c_ReadDistance(clientID, distanceObjectHandle, ct.byref(minimumDistance), operationMode), minimumDistance.value
749 |
750 | def simxRemoveObject(clientID, objectHandle, operationMode):
751 | '''
752 | Please have a look at the function description/documentation in the V-REP user manual
753 | '''
754 |
755 | return c_RemoveObject(clientID, objectHandle, operationMode)
756 |
757 | def simxRemoveModel(clientID, objectHandle, operationMode):
758 | '''
759 | Please have a look at the function description/documentation in the V-REP user manual
760 | '''
761 |
762 | return c_RemoveModel(clientID, objectHandle, operationMode)
763 |
764 | def simxRemoveUI(clientID, uiHandle, operationMode):
765 | '''
766 | Please have a look at the function description/documentation in the V-REP user manual
767 | '''
768 |
769 | return c_RemoveUI(clientID, uiHandle, operationMode)
770 |
771 | def simxCloseScene(clientID, operationMode):
772 | '''
773 | Please have a look at the function description/documentation in the V-REP user manual
774 | '''
775 |
776 | return c_CloseScene(clientID, operationMode)
777 |
778 | def simxGetObjects(clientID, objectType, operationMode):
779 | '''
780 | Please have a look at the function description/documentation in the V-REP user manual
781 | '''
782 |
783 | objectCount = ct.c_int()
784 | objectHandles = ct.POINTER(ct.c_int)()
785 |
786 | ret = c_GetObjects(clientID, objectType, ct.byref(objectCount), ct.byref(objectHandles), operationMode)
787 | handles = []
788 | if ret == 0:
789 | for i in range(objectCount.value):
790 | handles.append(objectHandles[i])
791 |
792 | return ret, handles
793 |
794 |
795 | def simxDisplayDialog(clientID, titleText, mainText, dialogType, initialText, titleColors, dialogColors, operationMode):
796 | '''
797 | Please have a look at the function description/documentation in the V-REP user manual
798 | '''
799 | if titleColors != None:
800 | c_titleColors = (ct.c_float*6)(*titleColors)
801 | else:
802 | c_titleColors = None
803 | if dialogColors != None:
804 | c_dialogColors = (ct.c_float*6)(*dialogColors)
805 | else:
806 | c_dialogColors = None
807 |
808 | c_dialogHandle = ct.c_int()
809 | c_uiHandle = ct.c_int()
810 | if sys.version_info[0] == 3:
811 | if type(titleText) is str:
812 | titleText=titleText.encode('utf-8')
813 | if type(mainText) is str:
814 | mainText=mainText.encode('utf-8')
815 | if type(initialText) is str:
816 | initialText=initialText.encode('utf-8')
817 | return c_DisplayDialog(clientID, titleText, mainText, dialogType, initialText, c_titleColors, c_dialogColors, ct.byref(c_dialogHandle), ct.byref(c_uiHandle), operationMode), c_dialogHandle.value, c_uiHandle.value
818 |
819 | def simxEndDialog(clientID, dialogHandle, operationMode):
820 | '''
821 | Please have a look at the function description/documentation in the V-REP user manual
822 | '''
823 |
824 | return c_EndDialog(clientID, dialogHandle, operationMode)
825 |
826 | def simxGetDialogInput(clientID, dialogHandle, operationMode):
827 | '''
828 | Please have a look at the function description/documentation in the V-REP user manual
829 | '''
830 | inputText = ct.POINTER(ct.c_char)()
831 | ret = c_GetDialogInput(clientID, dialogHandle, ct.byref(inputText), operationMode)
832 |
833 | a = bytearray()
834 | if ret == 0:
835 | i = 0
836 | while inputText[i] != b'\0':
837 | if sys.version_info[0] == 3:
838 | a.append(int.from_bytes(inputText[i],'big'))
839 | else:
840 | a.append(inputText[i])
841 | i = i+1
842 |
843 | if sys.version_info[0] == 3:
844 | a=str(a,'utf-8')
845 | else:
846 | a=str(a)
847 | return ret, a
848 |
849 |
850 | def simxGetDialogResult(clientID, dialogHandle, operationMode):
851 | '''
852 | Please have a look at the function description/documentation in the V-REP user manual
853 | '''
854 | result = ct.c_int()
855 | return c_GetDialogResult(clientID, dialogHandle, ct.byref(result), operationMode), result.value
856 |
857 | def simxCopyPasteObjects(clientID, objectHandles, operationMode):
858 | '''
859 | Please have a look at the function description/documentation in the V-REP user manual
860 | '''
861 | c_objectHandles = (ct.c_int*len(objectHandles))(*objectHandles)
862 | newObjectCount = ct.c_int()
863 | newObjectHandles = ct.POINTER(ct.c_int)()
864 | ret = c_CopyPasteObjects(clientID, c_objectHandles, len(objectHandles), ct.byref(newObjectHandles), ct.byref(newObjectCount), operationMode)
865 |
866 | newobj = []
867 | if ret == 0:
868 | for i in range(newObjectCount.value):
869 | newobj.append(newObjectHandles[i])
870 |
871 | return ret, newobj
872 |
873 |
874 | def simxGetObjectSelection(clientID, operationMode):
875 | '''
876 | Please have a look at the function description/documentation in the V-REP user manual
877 | '''
878 | objectCount = ct.c_int()
879 | objectHandles = ct.POINTER(ct.c_int)()
880 | ret = c_GetObjectSelection(clientID, ct.byref(objectHandles), ct.byref(objectCount), operationMode)
881 |
882 | newobj = []
883 | if ret == 0:
884 | for i in range(objectCount.value):
885 | newobj.append(objectHandles[i])
886 |
887 | return ret, newobj
888 |
889 |
890 |
891 | def simxSetObjectSelection(clientID, objectHandles, operationMode):
892 | '''
893 | Please have a look at the function description/documentation in the V-REP user manual
894 | '''
895 |
896 | c_objectHandles = (ct.c_int*len(objectHandles))(*objectHandles)
897 | return c_SetObjectSelection(clientID, c_objectHandles, len(objectHandles), operationMode)
898 |
899 | def simxClearFloatSignal(clientID, signalName, operationMode):
900 | '''
901 | Please have a look at the function description/documentation in the V-REP user manual
902 | '''
903 |
904 | if (sys.version_info[0] == 3) and (type(signalName) is str):
905 | signalName=signalName.encode('utf-8')
906 | return c_ClearFloatSignal(clientID, signalName, operationMode)
907 |
908 | def simxClearIntegerSignal(clientID, signalName, operationMode):
909 | '''
910 | Please have a look at the function description/documentation in the V-REP user manual
911 | '''
912 |
913 | if (sys.version_info[0] == 3) and (type(signalName) is str):
914 | signalName=signalName.encode('utf-8')
915 | return c_ClearIntegerSignal(clientID, signalName, operationMode)
916 |
917 | def simxClearStringSignal(clientID, signalName, operationMode):
918 | '''
919 | Please have a look at the function description/documentation in the V-REP user manual
920 | '''
921 |
922 | if (sys.version_info[0] == 3) and (type(signalName) is str):
923 | signalName=signalName.encode('utf-8')
924 | return c_ClearStringSignal(clientID, signalName, operationMode)
925 |
926 | def simxGetFloatSignal(clientID, signalName, operationMode):
927 | '''
928 | Please have a look at the function description/documentation in the V-REP user manual
929 | '''
930 |
931 | signalValue = ct.c_float()
932 | if (sys.version_info[0] == 3) and (type(signalName) is str):
933 | signalName=signalName.encode('utf-8')
934 | return c_GetFloatSignal(clientID, signalName, ct.byref(signalValue), operationMode), signalValue.value
935 |
936 | def simxGetIntegerSignal(clientID, signalName, operationMode):
937 | '''
938 | Please have a look at the function description/documentation in the V-REP user manual
939 | '''
940 |
941 | signalValue = ct.c_int()
942 | if (sys.version_info[0] == 3) and (type(signalName) is str):
943 | signalName=signalName.encode('utf-8')
944 | return c_GetIntegerSignal(clientID, signalName, ct.byref(signalValue), operationMode), signalValue.value
945 |
946 | def simxGetStringSignal(clientID, signalName, operationMode):
947 | '''
948 | Please have a look at the function description/documentation in the V-REP user manual
949 | '''
950 |
951 | signalLength = ct.c_int();
952 | signalValue = ct.POINTER(ct.c_ubyte)()
953 | if (sys.version_info[0] == 3) and (type(signalName) is str):
954 | signalName=signalName.encode('utf-8')
955 | ret = c_GetStringSignal(clientID, signalName, ct.byref(signalValue), ct.byref(signalLength), operationMode)
956 |
957 | a = bytearray()
958 | if ret == 0:
959 | for i in range(signalLength.value):
960 | a.append(signalValue[i])
961 | if sys.version_info[0] != 3:
962 | a=str(a)
963 |
964 | return ret, a
965 |
966 | def simxGetAndClearStringSignal(clientID, signalName, operationMode):
967 | '''
968 | Please have a look at the function description/documentation in the V-REP user manual
969 | '''
970 |
971 | signalLength = ct.c_int();
972 | signalValue = ct.POINTER(ct.c_ubyte)()
973 | if (sys.version_info[0] == 3) and (type(signalName) is str):
974 | signalName=signalName.encode('utf-8')
975 | ret = c_GetAndClearStringSignal(clientID, signalName, ct.byref(signalValue), ct.byref(signalLength), operationMode)
976 |
977 | a = bytearray()
978 | if ret == 0:
979 | for i in range(signalLength.value):
980 | a.append(signalValue[i])
981 | if sys.version_info[0] != 3:
982 | a=str(a)
983 |
984 | return ret, a
985 |
986 | def simxReadStringStream(clientID, signalName, operationMode):
987 | '''
988 | Please have a look at the function description/documentation in the V-REP user manual
989 | '''
990 |
991 | signalLength = ct.c_int();
992 | signalValue = ct.POINTER(ct.c_ubyte)()
993 | if (sys.version_info[0] == 3) and (type(signalName) is str):
994 | signalName=signalName.encode('utf-8')
995 | ret = c_ReadStringStream(clientID, signalName, ct.byref(signalValue), ct.byref(signalLength), operationMode)
996 |
997 | a = bytearray()
998 | if ret == 0:
999 | for i in range(signalLength.value):
1000 | a.append(signalValue[i])
1001 | if sys.version_info[0] != 3:
1002 | a=str(a)
1003 |
1004 | return ret, a
1005 |
1006 | def simxSetFloatSignal(clientID, signalName, signalValue, operationMode):
1007 | '''
1008 | Please have a look at the function description/documentation in the V-REP user manual
1009 | '''
1010 |
1011 | if (sys.version_info[0] == 3) and (type(signalName) is str):
1012 | signalName=signalName.encode('utf-8')
1013 | return c_SetFloatSignal(clientID, signalName, signalValue, operationMode)
1014 |
1015 | def simxSetIntegerSignal(clientID, signalName, signalValue, operationMode):
1016 | '''
1017 | Please have a look at the function description/documentation in the V-REP user manual
1018 | '''
1019 |
1020 | if (sys.version_info[0] == 3) and (type(signalName) is str):
1021 | signalName=signalName.encode('utf-8')
1022 | return c_SetIntegerSignal(clientID, signalName, signalValue, operationMode)
1023 |
1024 | def simxSetStringSignal(clientID, signalName, signalValue, operationMode):
1025 | '''
1026 | Please have a look at the function description/documentation in the V-REP user manual
1027 | '''
1028 |
1029 | sigV=signalValue
1030 | if sys.version_info[0] == 3:
1031 | if type(signalName) is str:
1032 | signalName=signalName.encode('utf-8')
1033 | if type(signalValue) is bytearray:
1034 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1035 | if type(signalValue) is str:
1036 | signalValue=signalValue.encode('utf-8')
1037 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1038 | else:
1039 | if type(signalValue) is bytearray:
1040 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1041 | if type(signalValue) is str:
1042 | signalValue=bytearray(signalValue)
1043 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1044 | sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
1045 | return c_SetStringSignal(clientID, signalName, sigV, len(signalValue), operationMode)
1046 |
1047 | def simxAppendStringSignal(clientID, signalName, signalValue, operationMode):
1048 | '''
1049 | Please have a look at the function description/documentation in the V-REP user manual
1050 | '''
1051 |
1052 | sigV=signalValue
1053 | if sys.version_info[0] == 3:
1054 | if type(signalName) is str:
1055 | signalName=signalName.encode('utf-8')
1056 | if type(signalValue) is bytearray:
1057 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1058 | if type(signalValue) is str:
1059 | signalValue=signalValue.encode('utf-8')
1060 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1061 | else:
1062 | if type(signalValue) is bytearray:
1063 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1064 | if type(signalValue) is str:
1065 | signalValue=bytearray(signalValue)
1066 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1067 | sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
1068 | return c_AppendStringSignal(clientID, signalName, sigV, len(signalValue), operationMode)
1069 |
1070 | def simxWriteStringStream(clientID, signalName, signalValue, operationMode):
1071 | '''
1072 | Please have a look at the function description/documentation in the V-REP user manual
1073 | '''
1074 |
1075 | sigV=signalValue
1076 | if sys.version_info[0] == 3:
1077 | if type(signalName) is str:
1078 | signalName=signalName.encode('utf-8')
1079 | if type(signalValue) is bytearray:
1080 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1081 | if type(signalValue) is str:
1082 | signalValue=signalValue.encode('utf-8')
1083 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1084 | else:
1085 | if type(signalValue) is bytearray:
1086 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1087 | if type(signalValue) is str:
1088 | signalValue=bytearray(signalValue)
1089 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1090 | sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
1091 | return c_WriteStringStream(clientID, signalName, sigV, len(signalValue), operationMode)
1092 |
1093 | def simxGetObjectFloatParameter(clientID, objectHandle, parameterID, operationMode):
1094 | '''
1095 | Please have a look at the function description/documentation in the V-REP user manual
1096 | '''
1097 |
1098 | parameterValue = ct.c_float()
1099 | return c_GetObjectFloatParameter(clientID, objectHandle, parameterID, ct.byref(parameterValue), operationMode), parameterValue.value
1100 |
1101 | def simxSetObjectFloatParameter(clientID, objectHandle, parameterID, parameterValue, operationMode):
1102 | '''
1103 | Please have a look at the function description/documentation in the V-REP user manual
1104 | '''
1105 |
1106 | return c_SetObjectFloatParameter(clientID, objectHandle, parameterID, parameterValue, operationMode)
1107 |
1108 | def simxGetObjectIntParameter(clientID, objectHandle, parameterID, operationMode):
1109 | '''
1110 | Please have a look at the function description/documentation in the V-REP user manual
1111 | '''
1112 |
1113 | parameterValue = ct.c_int()
1114 | return c_GetObjectIntParameter(clientID, objectHandle, parameterID, ct.byref(parameterValue), operationMode), parameterValue.value
1115 |
1116 | def simxSetObjectIntParameter(clientID, objectHandle, parameterID, parameterValue, operationMode):
1117 | '''
1118 | Please have a look at the function description/documentation in the V-REP user manual
1119 | '''
1120 |
1121 | return c_SetObjectIntParameter(clientID, objectHandle, parameterID, parameterValue, operationMode)
1122 |
1123 | def simxGetModelProperty(clientID, objectHandle, operationMode):
1124 | '''
1125 | Please have a look at the function description/documentation in the V-REP user manual
1126 | '''
1127 | prop = ct.c_int()
1128 | return c_GetModelProperty(clientID, objectHandle, ct.byref(prop), operationMode), prop.value
1129 |
1130 | def simxSetModelProperty(clientID, objectHandle, prop, operationMode):
1131 | '''
1132 | Please have a look at the function description/documentation in the V-REP user manual
1133 | '''
1134 |
1135 | return c_SetModelProperty(clientID, objectHandle, prop, operationMode)
1136 |
1137 | def simxStart(connectionAddress, connectionPort, waitUntilConnected, doNotReconnectOnceDisconnected, timeOutInMs, commThreadCycleInMs):
1138 | '''
1139 | Please have a look at the function description/documentation in the V-REP user manual
1140 | '''
1141 |
1142 | if (sys.version_info[0] == 3) and (type(connectionAddress) is str):
1143 | connectionAddress=connectionAddress.encode('utf-8')
1144 | return c_Start(connectionAddress, connectionPort, waitUntilConnected, doNotReconnectOnceDisconnected, timeOutInMs, commThreadCycleInMs)
1145 |
1146 | def simxFinish(clientID):
1147 | '''
1148 | Please have a look at the function description/documentation in the V-REP user manual
1149 | '''
1150 |
1151 | return c_Finish(clientID)
1152 |
1153 | def simxGetPingTime(clientID):
1154 | '''
1155 | Please have a look at the function description/documentation in the V-REP user manual
1156 | '''
1157 | pingTime = ct.c_int()
1158 | return c_GetPingTime(clientID, ct.byref(pingTime)), pingTime.value
1159 |
1160 | def simxGetLastCmdTime(clientID):
1161 | '''
1162 | Please have a look at the function description/documentation in the V-REP user manual
1163 | '''
1164 |
1165 | return c_GetLastCmdTime(clientID)
1166 |
1167 | def simxSynchronousTrigger(clientID):
1168 | '''
1169 | Please have a look at the function description/documentation in the V-REP user manual
1170 | '''
1171 |
1172 | return c_SynchronousTrigger(clientID)
1173 |
1174 | def simxSynchronous(clientID, enable):
1175 | '''
1176 | Please have a look at the function description/documentation in the V-REP user manual
1177 | '''
1178 |
1179 | return c_Synchronous(clientID, enable)
1180 |
1181 | def simxPauseCommunication(clientID, enable):
1182 | '''
1183 | Please have a look at the function description/documentation in the V-REP user manual
1184 | '''
1185 |
1186 | return c_PauseCommunication(clientID, enable)
1187 |
1188 | def simxGetInMessageInfo(clientID, infoType):
1189 | '''
1190 | Please have a look at the function description/documentation in the V-REP user manual
1191 | '''
1192 | info = ct.c_int()
1193 | return c_GetInMessageInfo(clientID, infoType, ct.byref(info)), info.value
1194 |
1195 | def simxGetOutMessageInfo(clientID, infoType):
1196 | '''
1197 | Please have a look at the function description/documentation in the V-REP user manual
1198 | '''
1199 | info = ct.c_int()
1200 | return c_GetOutMessageInfo(clientID, infoType, ct.byref(info)), info.value
1201 |
1202 | def simxGetConnectionId(clientID):
1203 | '''
1204 | Please have a look at the function description/documentation in the V-REP user manual
1205 | '''
1206 |
1207 | return c_GetConnectionId(clientID)
1208 |
1209 | def simxCreateBuffer(bufferSize):
1210 | '''
1211 | Please have a look at the function description/documentation in the V-REP user manual
1212 | '''
1213 |
1214 | return c_CreateBuffer(bufferSize)
1215 |
1216 | def simxReleaseBuffer(buffer):
1217 | '''
1218 | Please have a look at the function description/documentation in the V-REP user manual
1219 | '''
1220 |
1221 | return c_ReleaseBuffer(buffer)
1222 |
1223 | def simxTransferFile(clientID, filePathAndName, fileName_serverSide, timeOut, operationMode):
1224 | '''
1225 | Please have a look at the function description/documentation in the V-REP user manual
1226 | '''
1227 |
1228 | if (sys.version_info[0] == 3) and (type(filePathAndName) is str):
1229 | filePathAndName=filePathAndName.encode('utf-8')
1230 | return c_TransferFile(clientID, filePathAndName, fileName_serverSide, timeOut, operationMode)
1231 |
1232 | def simxEraseFile(clientID, fileName_serverSide, operationMode):
1233 | '''
1234 | Please have a look at the function description/documentation in the V-REP user manual
1235 | '''
1236 |
1237 | if (sys.version_info[0] == 3) and (type(fileName_serverSide) is str):
1238 | fileName_serverSide=fileName_serverSide.encode('utf-8')
1239 | return c_EraseFile(clientID, fileName_serverSide, operationMode)
1240 |
1241 | def simxCreateDummy(clientID, size, color, operationMode):
1242 | '''
1243 | Please have a look at the function description/documentation in the V-REP user manual
1244 | '''
1245 |
1246 | handle = ct.c_int()
1247 | if color != None:
1248 | c_color = (ct.c_ubyte*12)(*color)
1249 | else:
1250 | c_color = None
1251 | return c_CreateDummy(clientID, size, c_color, ct.byref(handle), operationMode), handle.value
1252 |
1253 | def simxQuery(clientID, signalName, signalValue, retSignalName, timeOutInMs):
1254 | '''
1255 | Please have a look at the function description/documentation in the V-REP user manual
1256 | '''
1257 |
1258 | retSignalLength = ct.c_int();
1259 | retSignalValue = ct.POINTER(ct.c_ubyte)()
1260 |
1261 | sigV=signalValue
1262 | if sys.version_info[0] == 3:
1263 | if type(signalName) is str:
1264 | signalName=signalName.encode('utf-8')
1265 | if type(retSignalName) is str:
1266 | retSignalName=retSignalName.encode('utf-8')
1267 | if type(signalValue) is bytearray:
1268 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1269 | if type(signalValue) is str:
1270 | signalValue=signalValue.encode('utf-8')
1271 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1272 | else:
1273 | if type(signalValue) is bytearray:
1274 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1275 | if type(signalValue) is str:
1276 | signalValue=bytearray(signalValue)
1277 | sigV = (ct.c_ubyte*len(signalValue))(*signalValue)
1278 | sigV=ct.cast(sigV,ct.POINTER(ct.c_ubyte)) # IronPython needs this
1279 |
1280 | ret = c_Query(clientID, signalName, sigV, len(signalValue), retSignalName, ct.byref(retSignalValue), ct.byref(retSignalLength), timeOutInMs)
1281 |
1282 | a = bytearray()
1283 | if ret == 0:
1284 | for i in range(retSignalLength.value):
1285 | a.append(retSignalValue[i])
1286 | if sys.version_info[0] != 3:
1287 | a=str(a)
1288 |
1289 | return ret, a
1290 |
1291 | def simxGetObjectGroupData(clientID, objectType, dataType, operationMode):
1292 | '''
1293 | Please have a look at the function description/documentation in the V-REP user manual
1294 | '''
1295 |
1296 | handles =[]
1297 | intData =[]
1298 | floatData =[]
1299 | stringData =[]
1300 | handlesC = ct.c_int()
1301 | handlesP = ct.POINTER(ct.c_int)()
1302 | intDataC = ct.c_int()
1303 | intDataP = ct.POINTER(ct.c_int)()
1304 | floatDataC = ct.c_int()
1305 | floatDataP = ct.POINTER(ct.c_float)()
1306 | stringDataC = ct.c_int()
1307 | stringDataP = ct.POINTER(ct.c_char)()
1308 | ret = c_GetObjectGroupData(clientID, objectType, dataType, ct.byref(handlesC), ct.byref(handlesP), ct.byref(intDataC), ct.byref(intDataP), ct.byref(floatDataC), ct.byref(floatDataP), ct.byref(stringDataC), ct.byref(stringDataP), operationMode)
1309 |
1310 | if ret == 0:
1311 | for i in range(handlesC.value):
1312 | handles.append(handlesP[i])
1313 | for i in range(intDataC.value):
1314 | intData.append(intDataP[i])
1315 | for i in range(floatDataC.value):
1316 | floatData.append(floatDataP[i])
1317 | s = 0
1318 | for i in range(stringDataC.value):
1319 | a = bytearray()
1320 | while stringDataP[s] != b'\0':
1321 | if sys.version_info[0] == 3:
1322 | a.append(int.from_bytes(stringDataP[s],'big'))
1323 | else:
1324 | a.append(stringDataP[s])
1325 | s += 1
1326 | s += 1 #skip null
1327 | if sys.version_info[0] == 3:
1328 | a=str(a,'utf-8')
1329 | else:
1330 | a=str(a)
1331 | stringData.append(a)
1332 |
1333 | return ret, handles, intData, floatData, stringData
1334 |
1335 | def simxGetObjectVelocity(clientID, objectHandle, operationMode):
1336 | '''
1337 | Please have a look at the function description/documentation in the V-REP user manual
1338 | '''
1339 | linearVel = (ct.c_float*3)()
1340 | angularVel = (ct.c_float*3)()
1341 | ret = c_GetObjectVelocity(clientID, objectHandle, linearVel, angularVel, operationMode)
1342 | arr1 = []
1343 | for i in range(3):
1344 | arr1.append(linearVel[i])
1345 | arr2 = []
1346 | for i in range(3):
1347 | arr2.append(angularVel[i])
1348 | return ret, arr1, arr2
1349 |
1350 | def simxPackInts(intList):
1351 | '''
1352 | Please have a look at the function description/documentation in the V-REP user manual
1353 | '''
1354 |
1355 | if sys.version_info[0] == 3:
1356 | s=bytes()
1357 | for i in range(len(intList)):
1358 | s=s+struct.pack('