mirror of
https://github.com/wassname/kair_algorithms_draft.git
synced 2026-10-27 12:50:17 +08:00
* Merge subin branch Squashed commit of the following: commit 98112b8c05f955b1eb49a6b78023cad0979d5f95 Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 18:19:46 2019 +0900 Remove noqa commit f45571a80afd403c8ec56db8a2fb5cbedf288db7 Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:50:39 2019 +0900 Resolve flake8 commit 058d85bc4ed09441d27065e6d304bfb946942a98 Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:41:35 2019 +0900 Modify structures of ros interface and reacher env commit ae4c859ffa6b008823050f310bdccbee6a1de30a Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:28:15 2019 +0900 Resolve flake8 commit 4c74ec6527b52d75882ddbe1b4f518f9c252a25c Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:23:30 2019 +0900 Resolve flake8 commit 243b2f3739b4388d814a886d5cf1b85a05bb526a Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:18:13 2019 +0900 Add open manipulator environment * Refactor openmanipulator environment class * Refactored env structure * Fix errors * Fix error * Add open_manipulator launch file * Fix errors * fix error * fix error * fix error * fix error * fix error * fix error * fix error * Fix typo * Delete unused script * Change reward * Fix typo, add env name to config * Change demo file compatible to python2 (#40) * Change demo file to python2 compatible * Add object to classes for compatibility with python2 * Refactoring config, envs and ros interface (#48) * Refactoring config architecture * Replace network hyper params on agent config * Modify env class and ros interface class * Modify getter and setter on ros interface * Modify wrong code * Fix typo * Add env config * Final environment class and test scripts before the test (#43) * new user branch * Resolve formatting issues on test scripts * Resolve formatting issues on test scripts * Merge subin branch Squashed commit of the following: commit 98112b8c05f955b1eb49a6b78023cad0979d5f95 Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 18:19:46 2019 +0900 Remove noqa commit f45571a80afd403c8ec56db8a2fb5cbedf288db7 Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:50:39 2019 +0900 Resolve flake8 commit 058d85bc4ed09441d27065e6d304bfb946942a98 Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:41:35 2019 +0900 Modify structures of ros interface and reacher env commit ae4c859ffa6b008823050f310bdccbee6a1de30a Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:28:15 2019 +0900 Resolve flake8 commit 4c74ec6527b52d75882ddbe1b4f518f9c252a25c Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:23:30 2019 +0900 Resolve flake8 commit 243b2f3739b4388d814a886d5cf1b85a05bb526a Author: Subin Yang <ysb8049@naver.com> Date: Sat Mar 30 17:18:13 2019 +0900 Add open manipulator environment * Refactor openmanipulator environment class * Test the training loop with td3 baseline * Add one-shot launch file for gazebo initialization * Refactored env structure * Fix errors * Fix error * Fix errors * fix error * fix error * fix error * fix error * fix error * fix error * fix error * Fix typo * Delete unused script * Change reward * Fix typo, add env name to config * Refactoring config, envs and ros interface (#48) * Refactoring config architecture * Replace network hyper params on agent config * Modify env class and ros interface class * Modify getter and setter on ros interface * Modify wrong code * Fix typo * Add env config * Resolve flake8, typo issue * Resolve conflict during pull remote
153 lines
5.1 KiB
Python
Executable File
153 lines
5.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
from math import cos, pi, sin
|
|
|
|
import numpy as np
|
|
|
|
import rospy
|
|
from config.environment import open_manipulator
|
|
from envs.open_manipulator import OpenManipulatorReacherEnv
|
|
from geometry_msgs.msg import Pose, Quaternion
|
|
from open_manipulator_msgs.msg import JointPosition, KinematicsPose
|
|
from open_manipulator_msgs.srv import SetJointPosition, SetKinematicsPose
|
|
|
|
overhead_orientation = Quaternion(
|
|
x=-0.00142460053167, y=0.999994209902, z=-0.00177030764765, w=0.00253311793936
|
|
)
|
|
|
|
cfg = open_manipulator
|
|
|
|
|
|
def test_reset():
|
|
env = OpenManipulatorReacherEnv(cfg)
|
|
_ = env.reset()
|
|
|
|
|
|
def test_forward():
|
|
env = OpenManipulatorReacherEnv(cfg)
|
|
_ = env.reset()
|
|
_pose = Pose()
|
|
_pose.position.x = 0.4
|
|
_pose.position.y = 0.0
|
|
_pose.position.z = 0.1
|
|
_pose.orientation.x = 0.0
|
|
_pose.orientation.y = 0.0
|
|
_pose.orientation.z = 0.0
|
|
_pose.orientation.w = 1.0
|
|
forward_pose = KinematicsPose()
|
|
forward_pose.pose = _pose
|
|
forward_pose.max_accelerations_scaling_factor = 0.0
|
|
forward_pose.max_velocity_scaling_factor = 0.0
|
|
forward_pose.tolerance = 0.0
|
|
try:
|
|
task_space_srv = rospy.ServiceProxy(
|
|
"/open_manipulator/goal_task_space_path", SetKinematicsPose
|
|
)
|
|
_ = task_space_srv("arm", "gripper", forward_pose, 2.0)
|
|
except rospy.ServiceException as e:
|
|
rospy.loginfo("Path planning service call failed: {0}".format(e))
|
|
|
|
|
|
def test_rotate():
|
|
_qpose = JointPosition()
|
|
_qpose.joint_name = ["joint1", "joint2", "joint3", "joint4"]
|
|
_qpose.position = [0.5, 0.0, 0.0, 0.5]
|
|
_qpose.max_accelerations_scaling_factor = 0.0
|
|
_qpose.max_velocity_scaling_factor = 0.0
|
|
try:
|
|
task_space_srv = rospy.ServiceProxy(
|
|
"/open_manipulator/goal_joint_space_path_from_present", SetJointPosition
|
|
)
|
|
_ = task_space_srv("arm", _qpose, 2.0)
|
|
except rospy.ServiceException, e:
|
|
rospy.loginfo("Path planning service call failed: {0}".format(e))
|
|
_qpose.position[0] += -1.0
|
|
_qpose.position[3] += -1.0
|
|
try:
|
|
_ = task_space_srv("arm", _qpose, 2.0)
|
|
except rospy.ServiceException, e:
|
|
rospy.loginfo("Path planning service call failed: {0}".format(e))
|
|
|
|
|
|
def test_block_loc():
|
|
env = OpenManipulatorReacherEnv(cfg)
|
|
for iter in range(20):
|
|
b_pose = Pose()
|
|
b_pose.position.x = np.random.uniform(0.15, 0.20)
|
|
b_pose.position.y = np.random.uniform(-0.2, 0.2)
|
|
b_pose.position.z = 0.00
|
|
b_pose.orientation = overhead_orientation
|
|
env.ros_interface.set_target_block()
|
|
rospy.sleep(2.0)
|
|
env.ros_interface.delete_target_block()
|
|
|
|
|
|
def test_achieve_goal():
|
|
env = OpenManipulatorReacherEnv(cfg)
|
|
for iter in range(20):
|
|
block_pose = Pose()
|
|
block_pose.position.x = np.random.uniform(0.25, 0.6)
|
|
block_pose.position.y = np.random.uniform(-0.4, 0.4)
|
|
block_pose.position.z = 0.00
|
|
block_pose.orientation = overhead_orientation
|
|
env.ros_interface.set_target_block(block_pose)
|
|
|
|
r_pose = Pose()
|
|
r_pose.position = block_pose.position
|
|
r_pose.position.z = 0.08
|
|
forward_pose = KinematicsPose()
|
|
forward_pose.pose = r_pose
|
|
forward_pose.max_accelerations_scaling_factor = 0.0
|
|
forward_pose.max_velocity_scaling_factor = 0.0
|
|
forward_pose.tolerance = 0.0
|
|
try:
|
|
task_space_srv = rospy.ServiceProxy(
|
|
"/open_manipulator/goal_task_space_path", SetKinematicsPose
|
|
)
|
|
_ = task_space_srv("arm", "gripper", forward_pose, 2.0)
|
|
except rospy.ServiceException, e:
|
|
rospy.loginfo("Path planning service call failed: {0}".format(e))
|
|
rospy.sleep(5.0)
|
|
env.ros_interface.delete_target_block()
|
|
|
|
|
|
def test_workspace_limit():
|
|
env = OpenManipulatorReacherEnv(cfg)
|
|
for iter in range(100):
|
|
_polar_rad = np.random.uniform(0.134, 0.32)
|
|
_polar_theta = np.random.uniform(-pi * 0.7 / 4, pi * 0.7 / 4)
|
|
|
|
block_pose = Pose()
|
|
block_pose.position.x = _polar_rad * cos(_polar_theta)
|
|
block_pose.position.y = _polar_rad * sin(_polar_theta)
|
|
block_pose.position.z = np.random.uniform(0.05, 0.28)
|
|
block_pose.orientation = overhead_orientation
|
|
env.ros_interface.set_target_block(block_pose)
|
|
|
|
r_pose = Pose()
|
|
r_pose.position = block_pose.position
|
|
forward_pose = KinematicsPose()
|
|
forward_pose.pose = r_pose
|
|
forward_pose.max_accelerations_scaling_factor = 0.0
|
|
forward_pose.max_velocity_scaling_factor = 0.0
|
|
forward_pose.tolerance = 0.0
|
|
try:
|
|
task_space_srv = rospy.ServiceProxy(
|
|
"/open_manipulator/goal_task_space_path", SetKinematicsPose
|
|
)
|
|
_ = task_space_srv("arm", "gripper", forward_pose, 3.0)
|
|
except rospy.ServiceException, e:
|
|
rospy.loginfo("Path planning service call failed: {0}".format(e))
|
|
rospy.sleep(3.0)
|
|
env.ros_interface.check_for_termination()
|
|
env.ros_interface.delete_target_block()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# test_reset()
|
|
# test_forward()
|
|
# test_rotate()
|
|
# test_block_loc()
|
|
# test_achieve_goal()
|
|
test_workspace_limit()
|