Skip to content

Commit 6bbb479

Browse files
committed
minor changes
1 parent 2d2f374 commit 6bbb479

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

IROS_experiments/person_controller_webots/src/person.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ def __init__(self, person_number):
4141

4242
def set_speed(self, data):
4343
########## In case the receibed speed is in the person frame ##########
44-
if time.time() - self.last_time_sent_velocity > self.time_between_velocity_commands:
45-
self.last_time_sent_velocity = time.time()
46-
person_orientation = self.person_node.getOrientation()
47-
orientation = math.atan2(person_orientation[0], person_orientation[1]) - math.pi / 2
48-
rotation_matrix = np.array(
49-
[[math.cos(orientation), -math.sin(orientation)], [math.sin(orientation), math.cos(orientation)]])
50-
lin_speed = np.array([data.axes[1].value * 2, 0])
51-
# if data.axes[1] > 0.1 or data.axes[1] < -0.1:
52-
# self.moving = True
53-
# else:
54-
# self.moving = False
55-
converted_speed = np.matmul(rotation_matrix, lin_speed)
56-
self.person_node.setVelocity(
57-
[converted_speed[0] / 2.5, converted_speed[1] / 2.5, 0, 0, 0, -data.axes[0].value * math.pi / 2])
44+
# if time.time() - self.last_time_sent_velocity > self.time_between_velocity_commands:
45+
# self.last_time_sent_velocity = time.time()
46+
person_orientation = self.person_node.getOrientation()
47+
orientation = math.atan2(person_orientation[0], person_orientation[1]) - math.pi / 2
48+
rotation_matrix = np.array(
49+
[[math.cos(orientation), -math.sin(orientation)], [math.sin(orientation), math.cos(orientation)]])
50+
lin_speed = np.array([data.axes[1].value * 2, 0])
51+
# if data.axes[1] > 0.1 or data.axes[1] < -0.1:
52+
# self.moving = True
53+
# else:
54+
# self.moving = False
55+
converted_speed = np.matmul(rotation_matrix, lin_speed)
56+
self.person_node.setVelocity(
57+
[converted_speed[0] / 2.5, converted_speed[1] / 2.5, 0, 0, 0, -data.axes[0].value * math.pi / 2])
5858

5959
def set_initial_pose(self, data):
6060
if data.buttons[3]:
@@ -65,6 +65,6 @@ def get_camera_image(self):
6565
color = self.person_camera.getImage()
6666
color_image = cv2.cvtColor(cv2.cvtColor(
6767
np.frombuffer(color, np.uint8).reshape(self.person_camera.getHeight(), self.person_camera.getWidth(), 4),
68-
cv2.COLOR_RGBA2RGB), cv2.COLOR_BGR2RGB)
68+
cv2.COLOR_BGR2RGB), cv2.COLOR_BGR2RGB)
6969
cv2.imshow("color", color_image)
7070
cv2.waitKey(1)

IROS_experiments/person_controller_webots/src/specificworker.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# You should have received a copy of the GNU General Public License
1919
# along with RoboComp. If not, see <http://www.gnu.org/licenses/>.
2020
#
21+
import time
2122

2223
from PySide2.QtCore import QTimer
2324
from PySide2.QtWidgets import QApplication
@@ -43,14 +44,14 @@
4344
class SpecificWorker(GenericWorker):
4445
def __init__(self, proxy_map, startup_check=False):
4546
super(SpecificWorker, self).__init__(proxy_map)
46-
self.Period = 100
47+
self.Period = 16
4748
if startup_check:
4849
self.startup_check()
4950
else:
5051
os.environ["WEBOTS_CONTROLLER_URL"] = "ipc://1234/HUMAN_" + str(1)
5152
self.person = Person(1)
5253

53-
self.speed_queue = deque(maxlen=10)
54+
self.speed_queue = deque(maxlen=1)
5455

5556
self.timer.timeout.connect(self.compute)
5657
self.timer.start(self.Period)
@@ -69,13 +70,16 @@ def setParams(self, params):
6970

7071
@QtCore.Slot()
7172
def compute(self):
72-
print(self.person.step(self.person.timeStep), self.person.timeStep)
73-
while self.person.step(self.person.timeStep) != -1:
74-
self.person.bvh_animation_functions.motion_step()
73+
# print(self.person.step(self.person.timeStep), self.person.timeStep)
74+
if self.person.step(self.person.timeStep) != -1:
75+
t1 = time.time()
76+
# self.person.bvh_animation_functions.motion_step()
7577
self.person.get_camera_image()
7678
if self.speed_queue:
77-
self.person.set_speed(self.speed_queue.pop())
78-
#
79+
self.person.set_speed(self.speed_queue.copy()[0])
80+
print("Speed set")
81+
print("TIME",time.time() - t1)
82+
7983

8084
def startup_check(self):
8185
print(f"Testing RoboCompJoystickAdapter.AxisParams from ifaces.RoboCompJoystickAdapter")

0 commit comments

Comments
 (0)