Skip to content

Commit ced7bff

Browse files
committed
File saving update
1 parent 6319cdd commit ced7bff

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

examples/Swift.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
"""
3+
@author Jesse Haviland
4+
"""
5+
6+
import roboticstoolbox as rp
7+
import spatialmath as sm
8+
import numpy as np
9+
import time
10+
11+
env = rp.backend.Swift()
12+
env.launch()
13+
14+
panda = rp.models.Panda()
15+
panda.q = panda.qr
16+
17+
Tep = panda.fkine() * sm.SE3.Tx(-0.2) * sm.SE3.Ty(0.2) * sm.SE3.Tz(0.2)
18+
19+
arrived = False
20+
env.add(panda)
21+
time.sleep(1)
22+
23+
dt = 0.05
24+
25+
env.record_start('file.webm')
26+
27+
while not arrived:
28+
29+
start = time.time()
30+
v, arrived = rp.p_servo(panda.fkine(), Tep, 1.0)
31+
panda.qd = np.linalg.pinv(panda.jacobe()) @ v
32+
env.step(5)
33+
stop = time.time()
34+
35+
if stop - start < dt:
36+
time.sleep(dt - (stop - start))
37+
38+
env.record_stop()
39+
40+
# Uncomment to stop the plot from closing
41+
# env.hold()

roboticstoolbox/backend/Sim/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

roboticstoolbox/backend/Sim/Sim.py renamed to roboticstoolbox/backend/Swift/Swift.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import numpy as np
1212

1313

14-
class Sim(Connector): # pragma nocover
14+
class Swift(Connector): # pragma nocover
1515

1616
def __init__(self):
17-
super(Sim, self).__init__()
17+
super(Swift, self).__init__()
1818

1919
# Popen(['npm', 'start', '--prefix', os.environ['SIM_ROOT']])
2020

@@ -33,8 +33,8 @@ def launch(self):
3333

3434
self.robots = []
3535

36-
self.sim = zerorpc.Client()
37-
self.sim.connect("tcp://127.0.0.1:4242")
36+
self.swift = zerorpc.Client()
37+
self.swift.connect("tcp://127.0.0.1:4242")
3838

3939
def step(self, dt=50):
4040
'''
@@ -102,7 +102,7 @@ def add(self, ob):
102102

103103
if isinstance(ob, rp.ETS):
104104
robot = ob.to_dict()
105-
id = self.sim.robot(robot)
105+
id = self.swift.robot(robot)
106106
self.robots.append(ob)
107107
return id
108108

@@ -142,5 +142,11 @@ def _step_robots(self, dt):
142142
def _draw_robots(self):
143143

144144
for i in range(len(self.robots)):
145-
self.robots[i].allfkine()
146-
self.sim.poses([i, self.robots[i].fk_dict()])
145+
self.robots[i].fkine_all()
146+
self.swift.poses([i, self.robots[i].fk_dict()])
147+
148+
def record_start(self, file):
149+
self.swift.record_start(file)
150+
151+
def record_stop(self):
152+
self.swift.record_stop(1)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from roboticstoolbox.backend.Swift.Swift import Swift
2+
3+
__all__ = [
4+
'Swift'
5+
]

roboticstoolbox/backend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
from roboticstoolbox.backend.urdf import *
33

44
try:
5-
from roboticstoolbox.backend.Sim import *
5+
from roboticstoolbox.backend.Swift import *
66
except ImportError:
77
pass

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy