Final Assignment  1.0
Research Track part 1 - Assignment 2 - RobEng A.A. 2020/2021
bug0 Namespace Reference

Functions

def new_random_target ()
 Get a new randomly-chosen target. More...
 
def change_state (state)
 Change the state of the node. More...
 
def normalize_angle (angle)
 Normalize an angle in [-pi, pi]. More...
 
def srv_bug0_switch (data)
 Turn on or off the node. More...
 
def srv_bug0_status (empty)
 Get the status of the service. More...
 
def clbk_odom (msg)
 Get the actual posture. More...
 
def clbk_laser (msg)
 Get the laser measurements. More...
 
def main ()
 The main section of the Bug0 algorithm. More...
 
def cbk_on_shutdown ()
 Called on the shutdown of the node. More...
 

Variables

string node_name = "bug0"
 name of this node More...
 
string name_bug0_switch = "/bug0_switch"
 name of the service 'bug0_switch' More...
 
string name_bug0_status = "/bug0_status"
 name of the service 'bug0_status' More...
 
string name_get_point = "/get_point"
 name of the service 'get_point' More...
 
 srv_get_point = None
 call-point of the service 'get_point' More...
 
bool service_active = False
 Is the service active? More...
 
bool only_once = False
 Only_once mode (see bug0_switch service) More...
 
 pub = None
 handler for the topic 'cmd_vel' (Publisher) More...
 
int yaw_ = 0
 Actual orientation wrt 'z' axis. More...
 
 position_ = Point()
 actual position More...
 
 desired_position_ = Point()
 target position More...
 
 regions_ = None
 Laser regions. More...
 
list state_desc_ = ['Go to point', 'wall following', 'target reached']
 Status labels. More...
 
int state_ = 0
 Actual status. More...
 
int err_pos = -1
 distance from the target More...
 
float max_tolerance_target = 0.5
 Tolerance on the distance from the target. More...
 
 srv_client_go_to_point_ = None
 call-point of the service 'go_to_point_switch' More...
 
 srv_client_wall_follower_ = None
 call-point of the service 'wall_follow_switch' More...
 
 sub_laser = rospy.Subscriber('/scan', LaserScan, clbk_laser)
 
 sub_odom = rospy.Subscriber('/odom', Odometry, clbk_odom)
 

Function Documentation

◆ cbk_on_shutdown()

def bug0.cbk_on_shutdown ( )

Called on the shutdown of the node.

Definition at line 399 of file bug0.py.

◆ change_state()

def bug0.change_state (   state)

Change the state of the node.

Parameters
state(Int) the next state.

The function changes the state of the robot from the actual one to the one passed as argument.

  • To state 0 : only go_to_point, wall_follow is turned off
  • To state 1 : only wall_follow, go_to_point is off
  • To state 2 : the robot is stopped, and a new target is required if the node is not in 'only_once' mode.

Definition at line 146 of file bug0.py.

◆ clbk_laser()

def bug0.clbk_laser (   msg)

Get the laser measurements.

Parameters
msg(sensor_msgs/LaserScan) raw-update from the lasers.

The function reads and adapts the informations from the topic '/scan'.
Used in managing states '1' and '2'

Definition at line 319 of file bug0.py.

◆ clbk_odom()

def bug0.clbk_odom (   msg)

Get the actual posture.

Parameters
msg(nsv_msgs/Odometry) the actual posture from the simulation.

The function reads and adapts the informations from the topic '/odom'.

Definition at line 293 of file bug0.py.

◆ main()

def bug0.main ( )

The main section of the Bug0 algorithm.

The state machine works in this way:

  • State 0 : go straight. If the robot has reached the target, go to state 2. If there is a wall opposite to the robot, go to state 1.
  • State 1 : follow the wall. If there is a way point, go to state 0. If the target is reached, go to state 2.
  • State 2 : read the new target from the parameter server. If the robot is already in the goal position, go to state 2. Otherwise, go to state 0.

Definition at line 344 of file bug0.py.

◆ new_random_target()

def bug0.new_random_target ( )

Get a new randomly-chosen target.

The only purpose of this function is requiring a new target from the /get_point server, and storing it into the parameter server. See /get_point .

Definition at line 120 of file bug0.py.

◆ normalize_angle()

def bug0.normalize_angle (   angle)

Normalize an angle in [-pi, pi].

Parameters
angle(float) the angle, in radiants
Returns
float the normalised angle

Definition at line 180 of file bug0.py.

◆ srv_bug0_status()

def bug0.srv_bug0_status (   empty)

Get the status of the service.

Parameters
empty(final_assignment/bug0_status) empty request

The function simply sends a message containing the most significant informations from the data section.
See /bug0_status .

Definition at line 267 of file bug0.py.

◆ srv_bug0_switch()

def bug0.srv_bug0_switch (   data)

Turn on or off the node.

Parameters
data(final_assignment/switch_serviceRequest) The request

Here is how this switch works:

  • If the request is to activate the service:
    • not success if the service is already active
    • otherwise, activate the service and return success to the caller.
  • If the request is to stop the service:
    • if the service is already turned off, return not succes.
    • Otherwise, the robot is immediately stopped, and the server is goes off. Return success

Definition at line 220 of file bug0.py.

Variable Documentation

◆ desired_position_

bug0.desired_position_ = Point()

target position

Definition at line 87 of file bug0.py.

◆ err_pos

int bug0.err_pos = -1

distance from the target

Definition at line 105 of file bug0.py.

◆ max_tolerance_target

float bug0.max_tolerance_target = 0.5

Tolerance on the distance from the target.

Definition at line 108 of file bug0.py.

◆ name_bug0_status

string bug0.name_bug0_status = "/bug0_status"

name of the service 'bug0_status'

Definition at line 63 of file bug0.py.

◆ name_bug0_switch

string bug0.name_bug0_switch = "/bug0_switch"

name of the service 'bug0_switch'

Definition at line 60 of file bug0.py.

◆ name_get_point

string bug0.name_get_point = "/get_point"

name of the service 'get_point'

Definition at line 66 of file bug0.py.

◆ node_name

string bug0.node_name = "bug0"

name of this node

Definition at line 57 of file bug0.py.

◆ only_once

bool bug0.only_once = False

Only_once mode (see bug0_switch service)

Definition at line 75 of file bug0.py.

◆ position_

bug0.position_ = Point()

actual position

Definition at line 84 of file bug0.py.

◆ pub

bug0.pub = None

handler for the topic 'cmd_vel' (Publisher)

Definition at line 78 of file bug0.py.

◆ regions_

bug0.regions_ = None

Laser regions.

Definition at line 90 of file bug0.py.

◆ service_active

bool bug0.service_active = False

Is the service active?

Definition at line 72 of file bug0.py.

◆ srv_client_go_to_point_

bug0.srv_client_go_to_point_ = None

call-point of the service 'go_to_point_switch'

Definition at line 190 of file bug0.py.

◆ srv_client_wall_follower_

bug0.srv_client_wall_follower_ = None

call-point of the service 'wall_follow_switch'

Definition at line 193 of file bug0.py.

◆ srv_get_point

bug0.srv_get_point = None

call-point of the service 'get_point'

Definition at line 69 of file bug0.py.

◆ state_

int bug0.state_ = 0

Actual status.

0 - go to point
1 - wall following
2 - goal reached

Definition at line 102 of file bug0.py.

◆ state_desc_

list bug0.state_desc_ = ['Go to point', 'wall following', 'target reached']

Status labels.

Definition at line 93 of file bug0.py.

◆ sub_laser

bug0.sub_laser = rospy.Subscriber('/scan', LaserScan, clbk_laser)

Definition at line 427 of file bug0.py.

◆ sub_odom

bug0.sub_odom = rospy.Subscriber('/odom', Odometry, clbk_odom)

Definition at line 428 of file bug0.py.

◆ yaw_

int bug0.yaw_ = 0

Actual orientation wrt 'z' axis.

Definition at line 81 of file bug0.py.