|
| 1 | +import numpy as np |
| 2 | +from bitbots_rl_motion.handlers.ball_handler import BallHandler |
| 3 | +from bitbots_rl_motion.handlers.joint_handler import JointHandler |
| 4 | +from bitbots_rl_motion.nodes.rl_node import RLNode |
| 5 | +from geometry_msgs.msg import PoseStamped |
| 6 | +from handlers.gravity_handler import GravityHandler |
| 7 | +from handlers.gyro_handler import GyroHandler |
| 8 | +from sensor_msgs.msg import Imu, JointState |
| 9 | + |
| 10 | +from bitbots_msgs.msg import JointCommand |
| 11 | + |
| 12 | + |
| 13 | +class KickNode(RLNode): |
| 14 | + def __init__(self, config_path: str): |
| 15 | + super().__init__(config_path) |
| 16 | + |
| 17 | + # loading model |
| 18 | + model = self._config["models"]["kick_model"] |
| 19 | + self.load_model(model) |
| 20 | + |
| 21 | + # publishers |
| 22 | + self._joint_command_pub = self.create_publisher(JointCommand, "walking_motor_goals", 10) |
| 23 | + |
| 24 | + # subscribers |
| 25 | + self._imu_sub = self.create_subscription(Imu, "imu/data", self._imu_callback, 10) |
| 26 | + self._joint_state_sub = self.create_subscription(JointState, "joint_states", self._joint_state_callback, 10) |
| 27 | + self._ball_pos_sub = self.create_subscription(PoseStamped, "ball_pos", self._ball_pos_callback, 10) |
| 28 | + |
| 29 | + # handlers |
| 30 | + self._gyro_handler = GyroHandler(self._config) |
| 31 | + self._gravity_handler = GravityHandler(self._config) |
| 32 | + self._joint_handler = JointHandler(self._config) |
| 33 | + self._ball_handler = BallHandler(self._config) |
| 34 | + |
| 35 | + # observations |
| 36 | + |
| 37 | + self._obs = np.hstack( |
| 38 | + [ |
| 39 | + self._gyro_handler.get_gyro(), |
| 40 | + self._gravity_handler.get_gravity(), |
| 41 | + self._joint_handler.get_velocity_data(), |
| 42 | + self._joint_handler.get_angle_data(), |
| 43 | + self._joint_handler.get_previous_action(), |
| 44 | + self._phase.get_phase(), |
| 45 | + self._ball_handler.get_ball_pos(), |
| 46 | + ] |
| 47 | + ).astype(np.float32) |
| 48 | + |
| 49 | + # callback functions |
| 50 | + |
| 51 | + def _imu_callback(self, msg): |
| 52 | + self._gyro_handler.imu_callback(msg) |
| 53 | + self._gravity_handler.imu_callback(msg) |
| 54 | + |
| 55 | + def _joint_state_callback(self, msg): |
| 56 | + self._joint_handler.joint_state_callback(msg) |
| 57 | + |
| 58 | + def _ball_pos_callback(self, msg): |
| 59 | + self._ball_handler.ball_pos_callback(msg) |
| 60 | + |
| 61 | + # load phase function |
| 62 | + |
| 63 | + def load_phase(self): |
| 64 | + pass |
| 65 | + |
| 66 | + # publisher function |
| 67 | + |
| 68 | + def publisher(self, onnx_pred): |
| 69 | + joint_command = self._joint_handler.get_joint_commands(onnx_pred) |
| 70 | + self._joint_command_pub.publish(joint_command) |
0 commit comments