Exemplo n.º 1
0
    def test_tf_change_locals(self):
        @nrp.MapVariable("shared_var", initial_value=2)
        @nrp.Neuron2Robot(Topic("/vars/shared1", float))
        def echo_shared_var(t, shared_var):
            shared_var.value = shared_var.value + t
            return shared_var.value

        @nrp.MapVariable("shared_var", initial_value=5)
        @nrp.Neuron2Robot(Topic("/vars/shared2", float))
        def echo_shared_var2(t, shared_var):
            shared_var.value = shared_var.value - t
            return shared_var.value

        nrp.initialize("MyTransferFunctions")

        topic1 = echo_shared_var.topic
        topic2 = echo_shared_var2.topic

        config.active_node.run_neuron_to_robot(1)
        config.active_node.run_robot_to_neuron(1)

        config.active_node.run_neuron_to_robot(2)
        config.active_node.run_robot_to_neuron(2)

        self.assertEqual(len(topic1.sent), 2)
        self.assertEqual(len(topic2.sent), 2)

        self.assertListEqual(topic1.sent, [3, 5])
        self.assertListEqual(topic2.sent, [4, 2])
    def test_rca_refresh_buffers(self, _, mock_init_node, mock_publisher):
        t1, t2 = Topic('a', 'b'), Topic('c', 'd')
        self.rca.register_publish_topic(t1)
        self.rca.register_publish_topic(t2)
        self.rca.initialize("test_node")
        self.rca.refresh_buffers(0.1)

        for key in self.rca.subscribed_topics:
            self.assertTrue(self.rca.subscribed_topics[key].changed)

        self.assertEquals(mock_init_node.call_count, 1)
        self.assertEquals(mock_publisher.call_count, 2)
 def test_rpt_send_message(self, mock_rospy_publisher):
     rpt = RosPublishedTopic(Topic('topic_name', 'topic_type'))
     pub = mock_rospy_publisher.return_value
     rpt.send_message('message')
     self.assertEquals(pub.publish.call_count, 1)
     self.assertEquals(pub.publish.call_args_list[0][0][0], 'message')
     rpt._unregister()
     rpt.send_message('message')
     self.assertEquals(pub.publish.call_count, 1)
Exemplo n.º 4
0
    def test_tf_globals(self):
        self.assertEquals(len(config.active_node.global_data), 0)

        @nrp.MapVariable("shared_var", initial_value=2, scope=nrp.GLOBAL)
        @nrp.Neuron2Robot(Topic("/vars/shared1", float))
        def echo_shared_var(t, shared_var):
            shared_var.value = shared_var.value + t
            return shared_var.value

        @nrp.MapVariable("shared_var", scope=nrp.GLOBAL)
        @nrp.Neuron2Robot(Topic("/vars/shared2", float))
        def echo_shared_var2(t, shared_var):
            shared_var.value = shared_var.value - t
            return shared_var.value

        @nrp.MapVariable("shared_var2",
                         global_key="second_var",
                         initial_value=5,
                         scope=nrp.GLOBAL)
        @nrp.Neuron2Robot(Topic("/vars/shared3", float))
        def echo_shared_var3(t, shared_var2):
            shared_var2.value = shared_var2.value - t
            return shared_var2.value

        nrp.initialize("MyTransferFunctions")

        self.assertEquals(len(config.active_node.global_data), 2)
        self.assertIn("shared_var", config.active_node.global_data)
        self.assertIn("second_var", config.active_node.global_data)

        topic1 = echo_shared_var.topic
        topic2 = echo_shared_var2.topic
        topic3 = echo_shared_var3.topic

        config.active_node.run_neuron_to_robot(1)
        config.active_node.run_neuron_to_robot(2)

        self.assertEqual(len(topic1.sent), 2)
        self.assertEqual(len(topic2.sent), 2)
        self.assertEqual(len(topic3.sent), 2)

        self.assertListEqual(topic1.sent, [3, 4])
        self.assertListEqual(topic2.sent, [2, 2])
        self.assertListEqual(topic3.sent, [4, 2])
Exemplo n.º 5
0
    def test_invalid_missing_param(self):
        with self.assertRaises(Exception):

            @nrp.MapVariable("shared_var_not_available",
                             initial_value=2,
                             scope=nrp.GLOBAL)
            @nrp.Neuron2Robot(Topic("/vars/shared1", float))
            def echo_shared_var(t, shared_var):
                shared_var.value = shared_var.value + t
                return shared_var.value
Exemplo n.º 6
0
    def test_invalid_scope(self):
        @nrp.MapVariable("shared_var",
                         initial_value=2,
                         scope="something_invalid")
        @nrp.Neuron2Robot(Topic("/vars/shared1", float))
        def echo_shared_var(t, shared_var):
            shared_var.value = shared_var.value + t
            return shared_var.value

        self.assertRaises(Exception, nrp.initialize, "MyTransferFunctions")
    def test_rca_create_topic_subscriber_triggers_tf(self, mock_rospy_subscriber, mock_init_node):
        self.rca.initialize("test_node")
        tf = Mock()
        tf.active = True
        tf.elapsed_time = 0
        tf.should_run.return_value = True
        tested_module.sim_time = 42.0

        sub = self.rca.create_topic_subscriber(Topic('topic', 'topic_type'))
        self.assertIsInstance(sub, RosSubscribedTopic)

        sub.register_tf_trigger(tf)
        sub._callback("foo")

        self.assertEqual(sub.value, "foo")
        tf.should_run.assert_called_once_with(42.0)
        tf.run.assert_called_once_with(42.0)
    def test_rca_create_topic_publisher(self, _, mock_rospy_publisher, mock_init_node):
        self.rca.initialize("test_node")

        r = self.rca.create_topic_publisher(PreprocessedTopic(
            'preprocessed_topic', 'topic_type', lambda x: ()
        ))
        self.assertIsInstance(r, RosPublishedPreprocessedTopic)

        r = self.rca.create_topic_publisher(Topic('topic', 'topic_type'))
        self.assertIsInstance(r, RosPublishedTopic)

        r = self.rca.create_topic_publisher("/rosout")
        self.assertIsInstance(r, RosPublishedTopic)

        with self.assertRaises(Exception):
            self.rca.create_topic_publisher("/does_not_exist")

        self.assertEquals(mock_init_node.call_count, 1)
        self.assertGreater(mock_rospy_publisher.call_count, 0)
Exemplo n.º 9
0
    def create_topic_publisher(self, topic, **config):
        """
        Creates a publisher object for the given topic

        :param topic: The topic
        :param config: Additional configuration for the publisher
        :param **queue_size: ROS Publisher queue_size parameter, please refer to ROS documentation

        :return: A publisher object
        """
        if isinstance(topic, PreprocessedTopic):
            return RosPublishedPreprocessedTopic(topic, **config)
        elif isinstance(topic, str):
            topic_type = self.get_topic_type(topic)
            if topic_type is None:
                raise Exception(
                    "The type of topic {0} is unknown. Please specify it explicitly"
                    .format(topic))
            topic = Topic(topic, topic_type)
        return RosPublishedTopic(topic, **config)
Exemplo n.º 10
0
    def create_topic_subscriber(self, topic, **config):
        """
        Creates the subscription object for the given topic

        :param topic: The topic
        :param config: Additional configuration for the subscriber
        :param **queue_size: ROS Subscriber queue_size parameter, please refer to ROS documentation
        :param **buff_size: ROS Subscriber buff_size parameter, please refer to ROS documentation

        :return: A subscription object
        """
        if isinstance(topic, PreprocessedTopic):
            return RosSubscribedPreprocessedTopic(
                topic, config.get('initial_value', None), **config)
        elif isinstance(topic, str):
            topic_type = self.get_topic_type(topic)
            if topic_type is None:
                raise Exception(
                    "The type of topic {0} is unknown. Please specify it explicitly"
                    .format(topic))
            topic = Topic(topic, topic_type)
        return RosSubscribedTopic(topic, config.get('initial_value', None),
                                  **config)
Exemplo n.º 11
0
 class Eye:
     camera = Topic("/husky1/sensors/camera1", list)
Exemplo n.º 12
0
 class LeftArm:
     twist = Topic("/husky1/leftArm/twist", float)
Exemplo n.º 13
0
 class RightArm:
     pose = Topic("/husky1/joint325/pose", float)
Exemplo n.º 14
0
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import logging


@nrp.MapRobotSubscriber("dist0",
                        Topic('/epuck/distanceSensor0', sensor_msgs.msg.Range))
@nrp.MapRobotSubscriber("dist1",
                        Topic('/epuck/distanceSensor1', sensor_msgs.msg.Range))
@nrp.MapRobotSubscriber("dist2",
                        Topic('/epuck/distanceSensor2', sensor_msgs.msg.Range))
@nrp.MapRobotSubscriber("dist3",
                        Topic('/epuck/distanceSensor3', sensor_msgs.msg.Range))
@nrp.MapRobotSubscriber("dist4",
                        Topic('/epuck/distanceSensor4', sensor_msgs.msg.Range))
@nrp.MapRobotSubscriber("dist5",
                        Topic('/epuck/distanceSensor5', sensor_msgs.msg.Range))
@nrp.MapRobotSubscriber("dist6",
                        Topic('/epuck/distanceSensor6', sensor_msgs.msg.Range))
@nrp.MapRobotSubscriber("dist7",
                        Topic('/epuck/distanceSensor7', sensor_msgs.msg.Range))
@nrp.MapSpikeSource("sensor_neurons", nrp.brain.sensors, nrp.raw_signal)
@nrp.Robot2Neuron()
def distances(t, dist0, dist1, dist2, dist3, dist4, dist5, dist6, dist7,
              sensor_neurons):
    """
    This transfer function detects the distance values taken from the epuck and direct them to brain
    """

    if dist5.value is not None and dist6.value is not None:
        sensor_neurons.value[0] = min(dist5.value.range,
Exemplo n.º 15
0
 def test_rst_init(self, mock_rospy_subscriber):
     RosSubscribedTopic(Topic('topic_name', 'topic_type'), None)
     self.assertEquals(mock_rospy_subscriber.call_count, 1)
     self.assertEquals(mock_rospy_subscriber.call_args_list[0][0][0], 'topic_name')
     self.assertEquals(mock_rospy_subscriber.call_args_list[0][0][1], 'topic_type')
     self.assertRaises(AssertionError, RosSubscribedTopic, None, None)
Exemplo n.º 16
0
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import geometry_msgs.msg

@nrp.MapVariable("sign", initial_value=None, scope=nrp.GLOBAL)
@nrp.Neuron2Robot(Topic('/husky/cmd_vel', geometry_msgs.msg.Twist))
def velo_control(t, sign):
	coeff = 6
	if sign.value == 'limit100':
		return geometry_msgs.msg.Twist(
        linear=geometry_msgs.msg.Vector3(x=1.0*coeff, y=0.0, z=0.0),
        angular=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=0.0))
	elif sign.value == 'limit20':
		return geometry_msgs.msg.Twist(
        linear=geometry_msgs.msg.Vector3(x=0.4*coeff, y=0.0, z=0.0),
        angular=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=0.0))
	elif sign.value == 'stop_sign':
		return geometry_msgs.msg.Twist(
        linear=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=0.0),
        angular=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=0.0))
	else:
		return geometry_msgs.msg.Twist(
        linear=geometry_msgs.msg.Vector3(x=0.6*coeff, y=0.0, z=0.0),
        angular=geometry_msgs.msg.Vector3(x=0.0, y=0.0, z=0.0))
Exemplo n.º 17
0
import gazebo_msgs.msg


@nrp.MapSpikeSink("left_wheel_forward_neuron", nrp.brain.actors[0],
                  nrp.population_rate)
@nrp.MapSpikeSink("left_wheel_back_neuron", nrp.brain.actors[1],
                  nrp.population_rate)
@nrp.MapSpikeSink("right_wheel_forward_neuron", nrp.brain.actors[2],
                  nrp.population_rate)
@nrp.MapSpikeSink("right_wheel_back_neuron", nrp.brain.actors[3],
                  nrp.population_rate)
@nrp.MapVariable("ideal_wheel_speed",
                 global_key="ideal_wheel_speed",
                 initial_value=[0.0, 0.0],
                 scope=nrp.GLOBAL)
@nrp.Neuron2Robot(Topic('/husky/wheel_speeds', gazebo_msgs.msg.WheelSpeeds))
def Brain2Motor(t, ideal_wheel_speed, left_wheel_forward_neuron,
                left_wheel_back_neuron, right_wheel_forward_neuron,
                right_wheel_back_neuron):
    """
    The transfer function which calculates the linear twist of the husky robot based on the
    voltage of left and right wheel neurons.
    :param t: the current simulation time
    :param left_wheel_forward_neuron: the left wheel forward neuron device
    :param left_wheel_back_neuron: the left wheel back neuron device
    :param right_wheel_forward_neuron: the right wheel forward neuron device
    :param right_wheel_back_neuron: the right wheel back neuron device
    :return: a gazebo_msgs/WheelSpeeds setting the speeds of the left and right pair of wheels of the husky robot for movement.
    """
    left_wheel = 0.002 * (left_wheel_forward_neuron.rate -
                          left_wheel_back_neuron.rate)
Exemplo n.º 18
0
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import std_msgs.msg
import geometry_msgs.msg


@nrp.MapRobotPublisher('direction_topic', Topic('direction_topic', std_msgs.msg.Int32))
@nrp.MapRobotSubscriber('position', Topic('/gazebo/model_states', gazebo_msgs.msg.ModelStates))
@nrp.MapVariable('initial_pose', global_key='initial_pose', initial_value=None)
@nrp.MapVariable('step_index', global_key='step_index', initial_value=0)
@nrp.MapVariable('direction', global_key='direction', initial_value=0)
@nrp.MapVariable('action', global_key='action', initial_value=-1)
@nrp.MapVariable('t_old', global_key='t_old', initial_value=0)
@nrp.Neuron2Robot(Topic('/husky/husky/cmd_vel', geometry_msgs.msg.Twist))
def move(t, step_index, position, initial_pose, direction_topic, direction, t_old, action):
    import math
    import rospy
    import numpy as np
    import tf

    linear = geometry_msgs.msg.Vector3(0, 0, 0)
    angular = geometry_msgs.msg.Vector3(0, 0, 0)

    if position.value is None:
        return geometry_msgs.msg.Twist(linear=linear, angular=angular)

    if initial_pose.value is None:
        initial_pose.value = position.value.pose[position.value.name.index('husky')]

    current_pose = position.value.pose[position.value.name.index('husky')]
    directions = [0, math.pi / 2, math.pi, math.pi * 3 / 2]
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import geometry_msgs.msg


@nrp.MapRobotSubscriber("pose",
                        Topic('/gazebo/model_states',
                              gazebo_msgs.msg.ModelStates))
@nrp.MapVariable("step_index", global_key="step_index", initial_value=0)
@nrp.MapVariable("initial_position",
                 global_key="initial_position",
                 initial_value=None)
@nrp.MapVariable("initial_orientation",
                 global_key="initial_orientation",
                 initial_value=None)
@nrp.MapVariable("waypoints", global_key="waypoints", initial_value=None)
@nrp.MapVariable("lattice_points",
                 global_key="lattice_points",
                 initial_value=None)
@nrp.MapVariable("stage", global_key="stage", initial_value=1)
@nrp.Neuron2Robot(Topic('/robot/cmd_vel', geometry_msgs.msg.Twist))
def navigate(t, step_index, pose, initial_position, initial_orientation,
             waypoints, lattice_points, stage):
    import math
    import numpy
    import csv
    from load_csv_positions import load_waypoints, load_lattice
    if lattice_points.value is None:
        # Load data of the SOM-lattice from a csv file
        lattice_points.value = load_lattice("resources/lattice.csv")
Exemplo n.º 20
0
 def test_rpt_init(self, mock_rospy_publisher):
     RosPublishedTopic(Topic('topic_name', 'topic_type'))
     self.assertEquals(mock_rospy_publisher.call_count, 1)
     self.assertEquals(mock_rospy_publisher.call_args_list[0][0][0], 'topic_name')
     self.assertEquals(mock_rospy_publisher.call_args_list[0][0][1], 'topic_type')
     self.assertRaises(AssertionError, RosPublishedTopic, None)
Exemplo n.º 21
0
 def test_rst_reset(self, mock_rospy_subscriber):
     rst = RosSubscribedTopic(Topic('topic_name', 'topic_type'), None)
     res = rst.reset(None)
     self.assertFalse(rst.changed)
     self.assertFalse(res.changed)
     self.assertEquals(mock_rospy_subscriber.call_count, 1)
Exemplo n.º 22
0
 def test_rst_callback(self, mock_rospy_subscriber):
     rst = RosSubscribedTopic(Topic('topic_name', 'topic_type'), 10)
     rst._callback('data')
     self.assertTrue(rst.changed)
     self.assertEquals(rst.value, 'data')
     self.assertEquals(mock_rospy_subscriber.call_count, 1)
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
from sensor_msgs.msg import JointState
import std_msgs.msg
from std_msgs.msg import Float64


@nrp.MapRobotSubscriber("joints", Topic("/icub/joints", JointState))
@nrp.Neuron2Robot(Topic('/icub/neck_yaw/vel', Float64))
def head_twist(t, joints):

    MAX_AMPLITUDE = 0.8
    RELATIVE_AMPLITUDE = 1.0

    joints = joints.value
    head_pos = joints.position[joints.name.index('neck_yaw')]

    desired_speed = -np.cos(
        t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE * 2.0 * 3.141592
    desired_pos = -np.sin(t * 2 * np.pi) * MAX_AMPLITUDE * RELATIVE_AMPLITUDE

    if desired_speed > 0:
        desired_speed *= (1 + (desired_pos - head_pos) * 2)
    else:
        desired_speed *= (1 - (desired_pos - head_pos) * 2)

    return std_msgs.msg.Float64(desired_speed)
@nrp.MapSpikeSink("arm_1_forward_neuron", nrp.brain.motors[0],
                  nrp.population_rate)
@nrp.MapSpikeSink("arm_2_forward_neuron", nrp.brain.motors[1],
                  nrp.population_rate)
@nrp.MapSpikeSink("arm_3_forward_neuron", nrp.brain.motors[2],
                  nrp.population_rate)
@nrp.MapSpikeSink("arm_4_forward_neuron", nrp.brain.motors[3],
                  nrp.population_rate)
@nrp.MapSpikeSink("arm_5_forward_neuron", nrp.brain.motors[4],
                  nrp.population_rate)
@nrp.MapSpikeSink("arm_6_forward_neuron", nrp.brain.motors[5],
                  nrp.population_rate)
@nrp.MapSpikeSink("hand_neuron", nrp.brain.motors[6], nrp.population_rate)
@nrp.MapRobotPublisher('arm_1',
                       Topic('/robot/arm_1_joint/cmd_pos',
                             std_msgs.msg.Float64))
@nrp.MapRobotPublisher('arm_2',
                       Topic('/robot/arm_2_joint/cmd_pos',
                             std_msgs.msg.Float64))
@nrp.MapRobotPublisher('arm_3',
                       Topic('/robot/arm_3_joint/cmd_pos',
                             std_msgs.msg.Float64))
@nrp.MapRobotPublisher('arm_4',
                       Topic('/robot/arm_4_joint/cmd_pos',
                             std_msgs.msg.Float64))
@nrp.MapRobotPublisher('arm_5',
                       Topic('/robot/arm_5_joint/cmd_pos',
                             std_msgs.msg.Float64))
@nrp.MapRobotPublisher('arm_6',
                       Topic('/robot/arm_6_joint/cmd_pos',
                             std_msgs.msg.Float64))
Exemplo n.º 25
0
# Imported Python Transfer Function
import numpy as np
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import geometry_msgs.msg
import cv2


#@nrp.MapSpikeSink('line_recorder', nrp.brain.actors, nrp.spike_recorder)
@nrp.MapRobotSubscriber("lastTerm_sub",
                        Topic("robot/lastTermTime", std_msgs.msg.Float64))
@nrp.MapRobotPublisher("lastTerm_writer",
                       Topic("robot/lastTermTime", std_msgs.msg.Float64))
@nrp.MapRobotSubscriber("invert", Topic("robot/invertStart",
                                        std_msgs.msg.Bool))
@nrp.MapRobotPublisher("invert_writer",
                       Topic("robot/invertStart", std_msgs.msg.Bool))
@nrp.MapRobotSubscriber("offsetHead",
                        Topic("/alphaS/offsetHead", std_msgs.msg.Float64))
@nrp.MapRobotSubscriber("offset", Topic("/alphaS/offset",
                                        std_msgs.msg.Float64))
@nrp.MapRobotSubscriber("type", Topic("/alphaS/gait_type",
                                      std_msgs.msg.String))
@nrp.MapRobotPublisher("joint_16",
                       Topic("/alphaS/joint_16/cmd_pos", std_msgs.msg.Float64))
@nrp.MapRobotPublisher("joint_15",
                       Topic("/alphaS/joint_15/cmd_pos", std_msgs.msg.Float64))
@nrp.MapRobotPublisher("joint_14",
                       Topic("/alphaS/joint_14/cmd_pos", std_msgs.msg.Float64))
@nrp.MapRobotPublisher("joint_13",
                       Topic("/alphaS/joint_13/cmd_pos", std_msgs.msg.Float64))
@nrp.MapRobotPublisher("joint_12",
Exemplo n.º 26
0
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import std_msgs.msg
from std_msgs.msg import Float64
@nrp.MapSpikeSink("agonist_neuron", nrp.brain.VN_agonist[slice(0,100,1)], nrp.population_rate, tau_fall = 20.0, tau_rise = 10.0)
@nrp.MapSpikeSink("antagonist_neuron", nrp.brain.VN_antagonist[slice(0,100,1)], nrp.population_rate, tau_fall = 20.0, tau_rise = 10.0)
#@nrp.MapSpikeSink("agonist_neuron", nrp.brain.VN_agonist[slice(0,100,1)], nrp.leaky_integrator_alpha, delay = 1.0, cm = 13.6)
#@nrp.MapSpikeSink("antagonist_neuron", nrp.brain.VN_antagonist[slice(0,100,1)], nrp.leaky_integrator_alpha, delay = 1.0, cm = 13.6)
@nrp.Neuron2Robot(Topic('/icub/eye_version/vel', Float64))
def eye_twist(t, agonist_neuron, antagonist_neuron):
    MAX_AMPLITUDE = 0.8
    eye_velocity=((agonist_neuron.rate - antagonist_neuron.rate)/(100.0*85.0))*MAX_AMPLITUDE*2.0*3.141592*1.55
        
    #clientLogger.info(t, agonist_neuron.rate, antagonist_neuron.rate, eye_velocity)
    if abs(eye_velocity)>MAX_AMPLITUDE*2.0*3.141592*1.55*1.2:
        sign=eye_velocity/(abs(eye_velocity))# + or -
        eye_velocity=MAX_AMPLITUDE*2.0*3.141592*1.5*1.2*sign   

    return std_msgs.msg.Float64(eye_velocity)
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
from geometry_msgs.msg import Twist, Vector3
'''
Transform actor neurons activity into velocity commands
'''


@nrp.MapSpikeSink("left_actor", nrp.brain.actors[1],
                  nrp.leaky_integrator_alpha)
@nrp.MapSpikeSink("right_actor", nrp.brain.actors[0],
                  nrp.leaky_integrator_alpha)
@nrp.Neuron2Robot(Topic("/robot/cmd_vel", geometry_msgs.msg.Twist))
def velocity_commands(t, right_actor, left_actor):
    # In abscence of activity, the vehicle is moving forward (magnitude lin_max)
    lin_max = 0.  ###_TO_DO_###
    # factor for the transformation from actor's voltage to linear translation component
    lin_factor = 0.  ###_TO_DO_###
    # linear translation component obtained by substrackting actors voltage
    x_lin = max(
        0, lin_max - lin_factor * (right_actor.voltage + left_actor.voltage))
    # factor for the transformation from actor's voltage to angular rotation component
    ang_factor = 0.  ###_TO_DO_###
    # angular rotation component as the actors voltage difference
    z_ang = ang_factor * (left_actor.voltage - right_actor.voltage)
    # print information on the log console
    if t % 2 < 0.02:
        clientLogger.info('linear x: {}, angular z: {}'.format(x_lin, z_ang))
    # build geometry messages
    Vlin = geometry_msgs.msg.Vector3(x_lin, 0, 0)
    Vang = geometry_msgs.msg.Vector3(0, 0, z_ang)
Exemplo n.º 28
0
"""
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
from std_msgs.msg import Float64


#This script is not necessary. It helps monitoring the monitoring wheel command.
@nrp.MapSpikeSink("right_wheel_neuron", nrp.brain.actors[1], nrp.raw_signal)
@nrp.Neuron2Robot(Topic('/right_velocity', std_msgs.msg.Float64))
def right_velocity(t, right_wheel_neuron):
    return std_msgs.msg.Float64(right_wheel_neuron.value)
import hbp_nrp_cle.tf_framework as nrp
from hbp_nrp_cle.robotsim.RobotInterface import Topic
import numpy as np
'''
Transmit laser scan information into sensory neuron activity:
The laser scan is composed of 360 beams, these beams are divided into 2 slices: right and left.
Sensory signals (laser values) are summed up and transformed by an activation function. 
The result is the rate of a Poisson generator that stimulates sensory neurons.
'''


@nrp.MapRobotSubscriber("laser",
                        Topic("/robot/p3dx/laser/scan",
                              sensor_msgs.msg.LaserScan))
@nrp.MapSpikeSource("right_sensor", nrp.brain.sensors[0], nrp.poisson)
@nrp.MapSpikeSource("left_sensor", nrp.brain.sensors[1], nrp.poisson)
@nrp.Robot2Neuron()
def laser_sensors_transmit(t, right_sensor, left_sensor, laser):
    # Handles None value
    if laser.value is None:
        left_sensor.rate = 100.
        return 0
    # Activation function definition
    def activation_fct(x, x_intercept, y_intercept):
        slope = -y_intercept / x_intercept
        return max(0, y_intercept + slope * x)

    ##_TO_DO_## Change 'idx_right' to modify the visual angle involved in the sensory process
    idx_right = 0  # first right beam index
    idx_middle = 180  # index separating left and right beams
    idx_left = 360 - idx_right  # last left beam index
Exemplo n.º 30
0
 def test_rpt_unregister(self, mock_rospy_publisher):
     rpt = RosPublishedTopic(Topic('topic_name', 'topic_type'))
     pub = mock_rospy_publisher.return_value
     rpt._unregister()
     self.assertEquals(pub.unregister.call_count, 1)