Skip to content

Commit 000b297

Browse files
Fixed python control loop example
Python code did not match robot program
1 parent 99a94ac commit 000b297

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

examples/example_control_loop.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2016, Universal Robots A/S,
2+
# Copyright (c) 2016-2022, Universal Robots A/S,
33
# All rights reserved.
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions are met:
@@ -72,24 +72,25 @@
7272
watchdog.input_int_register_0 = 0
7373

7474

75-
def setp_to_list(setp):
76-
list = []
75+
def setp_to_list(sp):
76+
sp_list = []
7777
for i in range(0, 6):
78-
list.append(setp.__dict__["input_double_register_%i" % i])
79-
return list
78+
sp_list.append(sp.__dict__["input_double_register_%i" % i])
79+
return sp_list
8080

8181

82-
def list_to_setp(setp, list):
82+
def list_to_setp(sp, list):
8383
for i in range(0, 6):
84-
setp.__dict__["input_double_register_%i" % i] = list[i]
85-
return setp
84+
sp.__dict__["input_double_register_%i" % i] = list[i]
85+
return sp
8686

8787

8888
# start data synchronization
8989
if not con.send_start():
9090
sys.exit()
9191

9292
# control loop
93+
move_completed = True
9394
while keep_running:
9495
# receive the current state
9596
state = con.receive()
@@ -98,11 +99,18 @@ def list_to_setp(setp, list):
9899
break
99100

100101
# do something...
101-
if state.output_int_register_0 != 0:
102+
if move_completed and state.output_int_register_0 == 1:
103+
move_completed = False
102104
new_setp = setp1 if setp_to_list(setp) == setp2 else setp2
103105
list_to_setp(setp, new_setp)
106+
print("New pose = " + str(new_setp))
104107
# send new setpoint
105108
con.send(setp)
109+
watchdog.input_int_register_0 = 1
110+
elif not move_completed and state.output_int_register_0 == 0:
111+
print("Move to confirmed pose = " + str(state.target_q))
112+
move_completed = True
113+
watchdog.input_int_register_0 = 0
106114

107115
# kick watchdog
108116
con.send(watchdog)

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.ur.rtde.client</groupId>
8-
<artifactId>python</artifactId>
9-
<version>2.7.1</version>
8+
<artifactId>rtde</artifactId>
9+
<version>2.7.2</version>
1010
<packaging>pom</packaging>
1111

1212
<properties>

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
setup(
2727
name="UrRtde",
2828
packages=["rtde"],
29-
version="2.7.1",
29+
version="2.7.2",
3030
description="Real-Time Data Exchange (RTDE) python client + examples",
3131
)

0 commit comments

Comments
 (0)