"""
This module contains the transfer function which is responsible for determining the linear twist
component of the husky's movement based on the left and right wheel neuron
"""
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import geometry_msgs.msg
@nrp.MapVariable("agent", initial_value=None, scope=nrp.GLOBAL)
@nrp.MapVariable("step", initial_value=False, scope=nrp.GLOBAL)
@nrp.MapVariable("bridge", initial_value=None, scope=nrp.GLOBAL)
#@nrp.MapSpikeSink("left_wheel_neuron", nrp.brain.actors[1], nrp.leaky_integrator_alpha)
#@nrp.MapSpikeSink("right_wheel_neuron", nrp.brain.actors[2], nrp.leaky_integrator_alpha)
#@nrp.Neuron2Robot(Topic('/husky/cmd_vel', geometry_msgs.msg.Twist))
@nrp.MapRobotPublisher("vel", Topic('/husky/cmd_vel', geometry_msgs.msg.Twist))
@nrp.MapRobotSubscriber("camera", Topic('/husky/camera', sensor_msgs.msg.Image))
def keras_rl_husky_linear_twist_forward(t, agent, step, bridge, vel, camera):
if step.value is False and bridge.value is not None and agent.value is not None:
# convert the ROS image to an OpenCV image and Numpy array for observation
cv_image = bridge.value.imgmsg_to_cv2(camera.value, "rgb8")
observation = np.expand_dims(cv_image, axis=0)
# get movement action from agent and publish to robot
action = agent.value.forward(observation)
vel.value.linear = geometry_msgs.msg.Vector3(x=action[0], y=0.0, z=0.0)
vel.value.angular = geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=action[1])
step.value = True
The agent is a keras-rl agent, which I create in another TF.
The bridge is a CvBridge, that I also initialize in the same TF as the agent.