Browse Source

Solve QT error and solve plotting issues

humble
hello-jesus 1 year ago
parent
commit
d6d7d844f0
1 changed files with 14 additions and 7 deletions
  1. +14
    -7
      stretch_ros_tutorials/effort_sensing.py

+ 14
- 7
stretch_ros_tutorials/effort_sensing.py View File

@ -4,9 +4,11 @@ import rclpy
import hello_helpers.hello_misc as hm import hello_helpers.hello_misc as hm
import os import os
import csv import csv
import time
import pandas as pd import pandas as pd
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import time
from matplotlib import animation from matplotlib import animation
from datetime import datetime from datetime import datetime
from control_msgs.action import FollowJointTrajectory from control_msgs.action import FollowJointTrajectory
@ -28,6 +30,8 @@ class JointActuatorEffortSensor(hm.HelloNode):
self.joint_effort = [] self.joint_effort = []
self.save_path = '/home/hello-robot/ament_ws/src/stretch_tutorials/stored_data' self.save_path = '/home/hello-robot/ament_ws/src/stretch_tutorials/stored_data'
self.export_data = export_data self.export_data = export_data
self.result = False
self.file_name = datetime.now().strftime("effort_sensing_tutorial_%Y%m%d%I")
def issue_command(self): def issue_command(self):
@ -46,6 +50,8 @@ class JointActuatorEffortSensor(hm.HelloNode):
trajectory_goal.trajectory.header.stamp = self.get_clock().now().to_msg() trajectory_goal.trajectory.header.stamp = self.get_clock().now().to_msg()
trajectory_goal.trajectory.header.frame_id = 'base_link' trajectory_goal.trajectory.header.frame_id = 'base_link'
while self.joint_state is None:
time.sleep(0.1)
self._send_goal_future = self.trajectory_client.send_goal_async(trajectory_goal, self.feedback_callback) self._send_goal_future = self.trajectory_client.send_goal_async(trajectory_goal, self.feedback_callback)
self.get_logger().info('Sent position goal = {0}'.format(trajectory_goal)) self.get_logger().info('Sent position goal = {0}'.format(trajectory_goal))
self._send_goal_future.add_done_callback(self.goal_response_callback) self._send_goal_future.add_done_callback(self.goal_response_callback)
@ -62,8 +68,8 @@ class JointActuatorEffortSensor(hm.HelloNode):
self._get_result_future.add_done_callback(self.get_result_callback) self._get_result_future.add_done_callback(self.get_result_callback)
def get_result_callback(self, future): def get_result_callback(self, future):
result = future.result().result
self.get_logger().info('Sent position goal = {0}'.format(result))
self.result = future.result().result
self.get_logger().info('Sent position goal = {0}'.format(self.result))
def feedback_callback(self, feedback_msg): def feedback_callback(self, feedback_msg):
""" """
@ -87,9 +93,9 @@ class JointActuatorEffortSensor(hm.HelloNode):
print("effort: " + str(current_effort)) print("effort: " + str(current_effort))
else: else:
self.joint_effort.append(current_effort) self.joint_effort.append(current_effort)
if self.export_data: if self.export_data:
file_name = datetime.now().strftime("%Y-%m-%d_%I-%p")
file_name = self.file_name
completeName = os.path.join(self.save_path, file_name) completeName = os.path.join(self.save_path, file_name)
with open(completeName, "w") as f: with open(completeName, "w") as f:
writer = csv.writer(f) writer = csv.writer(f)
@ -97,8 +103,9 @@ class JointActuatorEffortSensor(hm.HelloNode):
writer.writerows(self.joint_effort) writer.writerows(self.joint_effort)
def plot_data(self, animate = True): def plot_data(self, animate = True):
time.sleep(0.1)
file_name = datetime.now().strftime("%Y-%m-%d_%I-%p")
while not self.result:
time.sleep(0.1)
file_name = self.file_name
self.completeName = os.path.join(self.save_path, file_name) self.completeName = os.path.join(self.save_path, file_name)
self.data = pd.read_csv(self.completeName) self.data = pd.read_csv(self.completeName)
self.y_anim = [] self.y_anim = []

Loading…
Cancel
Save