Blocks.Teleoperator

 1import numpy as np
 2
 3def main(inputs, outputs, parameters, synchronise):
 4    '''
 5    ## Used to Imitate the Movements of the Operator
 6    It takes in an array as input, depending on the array variables, it will output another array
 7    containing the velocity it deems appropriate.
 8    The linear_velocity can be given via the `Linear` parameter.
 9
10    The output data is a list of the format: `[ linear_velocity, angular_velocity ]`\n
11    This is then shared to the output wire using the `share_array()` function.
12    
13    **Inputs**: Bounding Box (x, y, width, height)
14
15    **Outputs**: `cmd_vel` (linear velocity, angular velocity)
16
17    **Parameters**: Linear(Linear Velocity)
18    '''
19    auto_enable = True
20    try:
21        enable = inputs.read_number("Enable")
22    except Exception:
23        auto_enable = True
24
25    linear_velocity = parameters.read_number("Linear")
26
27    while(auto_enable or inputs.read_number('Enable')):
28        msg = inputs.read_array("Inp")
29
30        # (x, y, width, height)
31        x, y = float(msg[0]), float(msg[1])
32        x1, y1 = x+float(msg[2]), y+float(msg[3]) 
33
34        # Teleoperator Control Logic
35        cx = (x+x1)/2.0
36                
37        if cx < 320:
38            angular_velocity = -0.5
39        else:
40            angular_velocity = 0.5
41        
42        data = [linear_velocity, angular_velocity]
43        outputs.share_array("Out", data)
44        
45        synchronise()
def main(inputs, outputs, parameters, synchronise)
 4def main(inputs, outputs, parameters, synchronise):
 5    '''
 6    ## Used to Imitate the Movements of the Operator
 7    It takes in an array as input, depending on the array variables, it will output another array
 8    containing the velocity it deems appropriate.
 9    The linear_velocity can be given via the `Linear` parameter.
10
11    The output data is a list of the format: `[ linear_velocity, angular_velocity ]`\n
12    This is then shared to the output wire using the `share_array()` function.
13    
14    **Inputs**: Bounding Box (x, y, width, height)
15
16    **Outputs**: `cmd_vel` (linear velocity, angular velocity)
17
18    **Parameters**: Linear(Linear Velocity)
19    '''
20    auto_enable = True
21    try:
22        enable = inputs.read_number("Enable")
23    except Exception:
24        auto_enable = True
25
26    linear_velocity = parameters.read_number("Linear")
27
28    while(auto_enable or inputs.read_number('Enable')):
29        msg = inputs.read_array("Inp")
30
31        # (x, y, width, height)
32        x, y = float(msg[0]), float(msg[1])
33        x1, y1 = x+float(msg[2]), y+float(msg[3]) 
34
35        # Teleoperator Control Logic
36        cx = (x+x1)/2.0
37                
38        if cx < 320:
39            angular_velocity = -0.5
40        else:
41            angular_velocity = 0.5
42        
43        data = [linear_velocity, angular_velocity]
44        outputs.share_array("Out", data)
45        
46        synchronise()

Block Description

Used to Imitate the Movements of the Operator

It takes in an array as input, depending on the array variables, it will output another array containing the velocity it deems appropriate. The linear_velocity can be given via the Linear parameter.

The output data is a list of the format: [ linear_velocity, angular_velocity ]

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

Inputs: Bounding Box (x, y, width, height)

Outputs: cmd_vel (linear velocity, angular velocity)

Parameters: Linear(Linear Velocity)