Skip to content

Commit

Permalink
Fixed python control loop example
Browse files Browse the repository at this point in the history
Python code did not match robot program
  • Loading branch information
michal-milkowski committed Dec 20, 2022
1 parent 99a94ac commit 000b297
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 17 additions & 9 deletions examples/example_control_loop.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2016, Universal Robots A/S,
# Copyright (c) 2016-2022, Universal Robots A/S,
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -72,24 +72,25 @@
watchdog.input_int_register_0 = 0


def setp_to_list(setp):
list = []
def setp_to_list(sp):
sp_list = []
for i in range(0, 6):
list.append(setp.__dict__["input_double_register_%i" % i])
return list
sp_list.append(sp.__dict__["input_double_register_%i" % i])
return sp_list


def list_to_setp(setp, list):
def list_to_setp(sp, list):
for i in range(0, 6):
setp.__dict__["input_double_register_%i" % i] = list[i]
return setp
sp.__dict__["input_double_register_%i" % i] = list[i]
return sp


# start data synchronization
if not con.send_start():
sys.exit()

# control loop
move_completed = True
while keep_running:
# receive the current state
state = con.receive()
Expand All @@ -98,11 +99,18 @@ def list_to_setp(setp, list):
break

# do something...
if state.output_int_register_0 != 0:
if move_completed and state.output_int_register_0 == 1:
move_completed = False
new_setp = setp1 if setp_to_list(setp) == setp2 else setp2
list_to_setp(setp, new_setp)
print("New pose = " + str(new_setp))
# send new setpoint
con.send(setp)
watchdog.input_int_register_0 = 1
elif not move_completed and state.output_int_register_0 == 0:
print("Move to confirmed pose = " + str(state.target_q))
move_completed = True
watchdog.input_int_register_0 = 0

# kick watchdog
con.send(watchdog)
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

<modelVersion>4.0.0</modelVersion>
<groupId>com.ur.rtde.client</groupId>
<artifactId>python</artifactId>
<version>2.7.1</version>
<artifactId>rtde</artifactId>
<version>2.7.2</version>
<packaging>pom</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
setup(
name="UrRtde",
packages=["rtde"],
version="2.7.1",
version="2.7.2",
description="Real-Time Data Exchange (RTDE) python client + examples",
)

0 comments on commit 000b297

Please sign in to comment.