def test_modify_config_with_mqtt( self, throttle_config_controller_mqtt: ThrottleConfigController, mqtt_config: Client): use_steering, min_speed, max_speed, safe_angle, dangerous_angle = throttle_config_controller_mqtt.run( ) assert use_steering == False assert min_speed == 0.1 assert max_speed == 1.0 assert safe_angle == 0.2 assert dangerous_angle == 0.8 mqtt_config.publish(topic='test/car/config/throttle/min', payload="0.4", qos=1) \ .wait_for_publish() mqtt_config.publish(topic='test/car/config/throttle/max', payload="0.5", qos=1) \ .wait_for_publish() mqtt_config.publish(topic='test/car/config/throttle/angle/safe', payload="0.3", qos=1) \ .wait_for_publish() mqtt_config.publish(topic='test/car/config/throttle/angle/dangerous', payload="0.7", qos=1) \ .wait_for_publish() mqtt_config.publish(topic='test/car/config/throttle/compute_from_steering', payload="true", qos=1) \ .wait_for_publish() wait_all_mqtt_messages_consumed( f'mqtt-subscription-{throttle_config_controller_mqtt._mqtt_client_id}' f'qos{throttle_config_controller_mqtt.qos}') use_steering, min_speed, max_speed, safe_angle, dangerous_angle = throttle_config_controller_mqtt.run( ) assert use_steering == True assert min_speed == 0.4 assert max_speed == 0.5 assert safe_angle == 0.3 assert dangerous_angle == 0.7
def test_modify_config_min_max_with_mqtt( self, threshold_config_controller_mqtt: ThresholdConfigController, mqtt_config: Client): threshold_config_controller_mqtt.dynamic_enabled = False t_min, t_max, t_dynamic_enabled, t_default, t_delta, horizon = threshold_config_controller_mqtt.run( 100) assert t_min == 150 assert t_max == 200 wait_all_mqtt_messages_consumed( f'mqtt-subscription-{threshold_config_controller_mqtt._mqtt_client_id}' f'qos{threshold_config_controller_mqtt.qos}') msg = mqtt_config.publish(topic='test/car/config/threshold/min', payload="200", qos=1) msg.wait_for_publish() msg = mqtt_config.publish(topic='test/car/config/threshold/max', payload="220", qos=1) msg.wait_for_publish() wait_all_mqtt_messages_consumed( f'mqtt-subscription-{threshold_config_controller_mqtt._mqtt_client_id}' f'qos{threshold_config_controller_mqtt.qos}') t_min, t_max, t_dynamic_enabled, t_default, t_delta, horizon = threshold_config_controller_mqtt.run( 100) assert t_min == 200 assert t_max == 220
def road_config_controller( self, mqtt_address: Tuple[str, int]) -> Iterator[RoadConfigController]: host = mqtt_address[0] port = mqtt_address[1] wait_port_open(host=host, port=port) road_config = RoadConfigController( mqtt_enable=True, enable=True, horizon_hough_max_line_gap=10, horizon_hough_min_line_length=1, horizon_hough_threshold=100, kernel_size=4, morpho_iterations=3, canny_threshold1=120, canny_threshold2=250, approx_poly_epsilon_factor=0.01, mqtt_topic='test/car/config/road/#', mqtt_hostname=host, mqtt_port=port, mqtt_client_id='donkey-config-road-', mqtt_qos=1) wait_all_mqtt_messages_consumed( f'mqtt-subscription-{road_config._mqtt_client_id}' f'qos{road_config.qos}') yield road_config road_config.shutdown()
def fixture_angle_config_controller_mqtt( self, mqtt_address: (str, int)) -> AngleConfigController: angle_config = AngleConfigController( out_zone_percent=10, central_zone_percent=20, mqtt_enable=True, mqtt_topic='test/car/config/angle/#', mqtt_hostname=mqtt_address[0], mqtt_port=mqtt_address[1], mqtt_client_id='donkey-config-angle-', mqtt_qos=1) wait_all_mqtt_messages_consumed( f'mqtt-subscription-{angle_config._mqtt_client_id}' f'qos{angle_config.qos}') yield angle_config angle_config.shutdown()
def test_run(self, threshold_value_config: ThresholdValueEstimatorConfig, mqtt_config: Client): centroid_value = threshold_value_config.run() assert centroid_value == 120 wait_all_mqtt_messages_consumed( f'mqtt-subscription-{threshold_value_config._mqtt_client_id}' f'qos{threshold_value_config.qos}') mqtt_config.publish( topic='test/car/config/threshold_value_estimator/centroid_value', payload="220", qos=1).wait_for_publish() wait_all_mqtt_messages_consumed( f'mqtt-subscription-{threshold_value_config._mqtt_client_id}' f'qos{threshold_value_config.qos}') centroid_value = threshold_value_config.run() assert centroid_value == 220
def fixture_throttle_config_controller_mqtt(self, mqtt_address): throttle_config = ThrottleConfigController( min_speed=0.1, max_speed=1, safe_angle=0.2, dangerous_angle=0.8, use_steering=False, mqtt_enable=True, mqtt_hostname=mqtt_address[0], mqtt_port=mqtt_address[1], mqtt_qos=1, mqtt_client_id='donkey-config-throttle-', mqtt_topic='test/car/config/throttle/#') wait_all_mqtt_messages_consumed( f'mqtt-subscription-{throttle_config._mqtt_client_id}' f'qos{throttle_config.qos}') yield throttle_config throttle_config.shutdown()
def test_modify_config_dynamic_with_mqtt( self, threshold_config_controller_mqtt: ThresholdConfigController, mqtt_config: Client): threshold_config_controller_mqtt.dynamic_enabled = False t_min, t_max, t_dynamic_enabled, t_default, t_delta, horizon = threshold_config_controller_mqtt.run( 100) assert t_min == 150 assert t_max == 200 assert t_dynamic_enabled == False assert t_default == 160 assert t_delta == 20 assert horizon == 0.0 wait_all_mqtt_messages_consumed( f'mqtt-subscription-{threshold_config_controller_mqtt._mqtt_client_id}' f'qos{threshold_config_controller_mqtt.qos}') mqtt_config.publish(topic='test/car/config/threshold/default', payload="200", qos=1).wait_for_publish() mqtt_config.publish(topic='test/car/config/threshold/delta', payload="5", qos=1).wait_for_publish() mqtt_config.publish(topic='test/car/config/threshold/dynamic_enabled', payload="true", qos=1).wait_for_publish() mqtt_config.publish(topic='test/car/config/threshold/horizon', payload="0.5", qos=1).wait_for_publish() wait_all_mqtt_messages_consumed( f'mqtt-subscription-{threshold_config_controller_mqtt._mqtt_client_id}' f'qos{threshold_config_controller_mqtt.qos}') t_min, t_max, t_dynamic_enabled, t_default, t_delta, horizon = threshold_config_controller_mqtt.run( 100) assert t_min == 95 assert t_max == 105 assert t_dynamic_enabled == True assert t_default == 100 assert t_delta == 5 assert horizon == 0.5
def test_config(self, config_contours: ContoursConfigController, mqtt_config: Client): poly_dp_min, poly_dp_max, arc_length_min, arc_length_max = config_contours.run( ) assert arc_length_min == 10 assert arc_length_max == 100000 assert poly_dp_min == 4 assert poly_dp_max == 100 wait_all_mqtt_messages_consumed( f'mqtt-subscription-{config_contours._mqtt_client_id}' f'qos{config_contours.qos}') mqtt_config.publish(topic='test/car/config/contours/arc_length_min', payload="1", qos=1).wait_for_publish() mqtt_config.publish(topic='test/car/config/contours/arc_length_max', payload="10", qos=1).wait_for_publish() mqtt_config.publish(topic='test/car/config/contours/poly_dp_min', payload="5", qos=1).wait_for_publish() mqtt_config.publish(topic='test/car/config/contours/poly_dp_max', payload="20", qos=1).wait_for_publish() wait_all_mqtt_messages_consumed( f'mqtt-subscription-{config_contours._mqtt_client_id}' f'qos{config_contours.qos}') poly_dp_min, poly_dp_max, arc_length_min, arc_length_max = config_contours.run( ) assert arc_length_min == 1 assert arc_length_max == 10 assert poly_dp_min == 5 assert poly_dp_max == 20
def test_values(self, angle_config_controller: AngleConfigController, mqtt_config: Client): number_centroids_to_use, out_zone_percent, central_zone_percent = angle_config_controller.run( ) assert number_centroids_to_use == 1 assert out_zone_percent == 10 assert central_zone_percent == 20 mqtt_config.publish(topic='test/car/config/angle/number_centroids_to_use', payload="5", qos=1) \ .wait_for_publish() mqtt_config.publish(topic='test/car/config/angle/out_zone_percent', payload="50", qos=1) \ .wait_for_publish() mqtt_config.publish(topic='test/car/config/angle/central_zone_percent', payload="60", qos=1) \ .wait_for_publish() wait_all_mqtt_messages_consumed( f'mqtt-subscription-{angle_config_controller._mqtt_client_id}' f'qos{angle_config_controller.qos}') number_centroids_to_use, out_zone_percent, central_zone_percent = angle_config_controller.run( ) assert number_centroids_to_use == 5 assert out_zone_percent == 50 assert central_zone_percent == 60
def test_values(self, config: RoadConfigController, mqtt_config: Client): enable, horizon_hough_min_line_length, horizon_hough_max_line_gap, horizon_hough_threshold, kernel_size, \ morpho_iterations, canny_threshold1, canny_threshold2, approx_poly_epsilon_factor = config.run() assert enable == True assert horizon_hough_min_line_length == 1 assert horizon_hough_max_line_gap == 10 assert horizon_hough_threshold == 100 assert kernel_size == 4 assert morpho_iterations == 3 assert canny_threshold1 == 120 assert canny_threshold2 == 250 assert approx_poly_epsilon_factor == 0.01 mqtt_config.publish( topic=f'test/car/config/{CFG_ROAD_ENABLE.replace("cfg/", "")}', payload="false", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_HORIZON_HOUGH_MIN_LINE_LENGTH.replace("cfg/", "")}', payload="10", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_HORIZON_HOUGH_MAX_LINE_GAP.replace("cfg/", "")}', payload="5", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_HORIZON_HOUGH_THRESHOLD.replace("cfg/", "")}', payload="20", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_CONTOUR_KERNEL_SIZE.replace("cfg/", "")}', payload="30", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_CONTOUR_MORPHO_ITERATIONS.replace("cfg/", "")}', payload="40", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_CONTOUR_CANNY_THRESHOLD1.replace("cfg/", "")}', payload="50", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_CONTOUR_CANNY_THRESHOLD2.replace("cfg/", "")}', payload="60", qos=1).wait_for_publish() mqtt_config.publish( topic= f'test/car/config/{CFG_ROAD_CONTOUR_APPROX_POLY_EPSILON_FACTOR.replace("cfg/", "")}', payload="70.5", qos=1).wait_for_publish() wait_all_mqtt_messages_consumed( f'mqtt-subscription-{config._mqtt_client_id}' f'qos{config.qos}') enable, horizon_hough_min_line_length, horizon_hough_max_line_gap, horizon_hough_threshold, kernel_size, \ morpho_iterations, canny_threshold1, canny_threshold2, approx_poly_epsilon_factor = config.run() assert enable == False assert horizon_hough_min_line_length == 10 assert horizon_hough_max_line_gap == 5 assert horizon_hough_threshold == 20 assert kernel_size == 30 assert morpho_iterations == 40 assert canny_threshold1 == 50 assert canny_threshold2 == 60 assert approx_poly_epsilon_factor == 70.5