Blocks.Odometer

 1import numpy as np
 2import rospy
 3from turtlesim.msg import Pose
 4
 5x, y, yaw = 0.0, 0.0, 0.0
 6
 7def callback(msg):
 8    global x, y, yaw
 9    x = msg.x
10    y = msg.y
11    yaw = msg.theta
12
13def main(inputs, outputs, parameters, synchronise):
14    '''
15    ## Reads Data from An Odometer
16    It reads the ROSTopic name from the `ROSTopic` parameter.
17    It then initializes a Subscriber to subscribe to that ROSTopic, once the data is obtained through the callback
18    function, it is formatted into an array with the format: `[ x, y, yaw ]`\n
19    This data is then shared to the wire using the `share_array()` function.
20    
21    **Inputs**: None
22
23    **Outputs**: Array [X, Y, Yaw]
24
25    **Parameters**: ROSTopic
26    '''
27    rospy.init_node("odometerVC", anonymous=True)
28    rostopic_name = parameters.read_string("ROSTopic")
29    odometer_subscriber = rospy.Subscriber(rostopic_name, Pose, callback)
30
31    auto_enable = False
32    try:
33        enable = inputs.read_number("Enable")
34    except Exception:
35        auto_enable = True
36
37    while(auto_enable or inputs.read_number('Enable') and not rospy.is_shutdown()):
38        data = [x, y, yaw]
39
40        outputs.share_array("Out", data)
41
42        synchronise()
def callback(msg)
 8def callback(msg):
 9    global x, y, yaw
10    x = msg.x
11    y = msg.y
12    yaw = msg.theta
def main(inputs, outputs, parameters, synchronise)
14def main(inputs, outputs, parameters, synchronise):
15    '''
16    ## Reads Data from An Odometer
17    It reads the ROSTopic name from the `ROSTopic` parameter.
18    It then initializes a Subscriber to subscribe to that ROSTopic, once the data is obtained through the callback
19    function, it is formatted into an array with the format: `[ x, y, yaw ]`\n
20    This data is then shared to the wire using the `share_array()` function.
21    
22    **Inputs**: None
23
24    **Outputs**: Array [X, Y, Yaw]
25
26    **Parameters**: ROSTopic
27    '''
28    rospy.init_node("odometerVC", anonymous=True)
29    rostopic_name = parameters.read_string("ROSTopic")
30    odometer_subscriber = rospy.Subscriber(rostopic_name, Pose, callback)
31
32    auto_enable = False
33    try:
34        enable = inputs.read_number("Enable")
35    except Exception:
36        auto_enable = True
37
38    while(auto_enable or inputs.read_number('Enable') and not rospy.is_shutdown()):
39        data = [x, y, yaw]
40
41        outputs.share_array("Out", data)
42
43        synchronise()

Block Description

Reads Data from An Odometer

It reads the ROSTopic name from the ROSTopic parameter. It then initializes a Subscriber to subscribe to that ROSTopic, once the data is obtained through the callback function, it is formatted into an array with the format: [ x, y, yaw ]

This data is then shared to the wire using the share_array() function.

Inputs: None

Outputs: Array [X, Y, Yaw]

Parameters: ROSTopic