From 98e43aba494f9503a5a33309323d504f629ef27e Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Tue, 20 Oct 2020 11:31:16 +0300 Subject: [PATCH] docs: python 3 updates --- docs/en/aruco_marker.md | 4 ++-- docs/en/camera.md | 2 +- docs/en/cli.md | 2 +- docs/en/laser.md | 2 +- docs/en/migrate22.md | 2 +- docs/en/programming.md | 4 ++-- docs/en/ros.md | 2 +- docs/en/simple_offboard.md | 10 +++++----- docs/en/snippets.md | 2 +- docs/en/sonar.md | 4 ++-- docs/ru/aruco_marker.md | 4 ++-- docs/ru/camera.md | 2 +- docs/ru/cli.md | 2 +- docs/ru/laser.md | 2 +- docs/ru/migrate22.md | 2 +- docs/ru/programming.md | 4 ++-- docs/ru/ros.md | 2 +- docs/ru/simple_offboard.md | 10 +++++----- docs/ru/snippets.md | 2 +- docs/ru/sonar.md | 4 ++-- 20 files changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/en/aruco_marker.md b/docs/en/aruco_marker.md index c75568a4..7c1c218b 100644 --- a/docs/en/aruco_marker.md +++ b/docs/en/aruco_marker.md @@ -98,9 +98,9 @@ rospy.init_node('my_node') # ... def markers_callback(msg): - print 'Detected markers:': + print('Detected markers:'): for marker in msg.markers: - print 'Marker: %s' % marker + print('Marker: %s' % marker) # Create a Subscription object. Each time a message is posted in aruco_detect/markers, the markers_callback function is called with this message as its argument. rospy.Subscriber('aruco_detect/markers', MarkerArray, markers_callback) diff --git a/docs/en/camera.md b/docs/en/camera.md index 0308b6ed..a1d75325 100644 --- a/docs/en/camera.md +++ b/docs/en/camera.md @@ -138,7 +138,7 @@ def image_callback(data): (x, y, w, h) = barcode.rect xc = x + w/2 yc = y + h/2 - print ("Found {} with data {} with center at x={}, y={}".format(b_type, b_data, xc, yc)) + print("Found {} with data {} with center at x={}, y={}".format(b_type, b_data, xc, yc)) image_sub = rospy.Subscriber('main_camera/image_raw', Image, image_callback, queue_size=1) diff --git a/docs/en/cli.md b/docs/en/cli.md index 6f634f10..3db1fc1e 100644 --- a/docs/en/cli.md +++ b/docs/en/cli.md @@ -39,7 +39,7 @@ cat file.py Run `file.py` as a Python script: ```bash -python file.py +python3 file.py ``` Reboot Raspberry Pi: diff --git a/docs/en/laser.md b/docs/en/laser.md index 283fd0c1..59dd1cb6 100644 --- a/docs/en/laser.md +++ b/docs/en/laser.md @@ -59,7 +59,7 @@ rospy.init_node('flight') def range_callback(msg): # Process data from the rangefinder - print 'Rangefinder distance:', msg.range + print('Rangefinder distance:', msg.range) rospy.Subscriber('rangefinder/range', Range, range_callback) diff --git a/docs/en/migrate22.md b/docs/en/migrate22.md index c788796a..07b4120f 100644 --- a/docs/en/migrate22.md +++ b/docs/en/migrate22.md @@ -19,7 +19,7 @@ python3 flight.py Python 3 has certain syntax differences in comparison with the old version. Instead of `print` *operator*: ```python -print 'Clover is the best' +print 'Clover is the best' # this won't work ``` use `print` *function*: diff --git a/docs/en/programming.md b/docs/en/programming.md index cbd04bc3..f85d3465 100644 --- a/docs/en/programming.md +++ b/docs/en/programming.md @@ -34,10 +34,10 @@ Read more in the [GPS connection](gps.md) article. > **Info** For studying Python programming language, see [tutorial](https://www.learnpython.org/en/Welcome). -After you've configured your positioning system, you can start writing programs for autonomous flights. Use the [SSH connection to the Raspberry Pi](ssh.md) to run your scripts. In order to run a Python script use the `python` command: +After you've configured your positioning system, you can start writing programs for autonomous flights. Use the [SSH connection to the Raspberry Pi](ssh.md) to run your scripts. In order to run a Python script use the `python3` command: ```bash -python flight.py +python3 flight.py ``` Below is a complete flight program that performs a takeoff, flies forward and lands: diff --git a/docs/en/ros.md b/docs/en/ros.md index 6753a2dc..ecc1a3e9 100644 --- a/docs/en/ros.md +++ b/docs/en/ros.md @@ -63,7 +63,7 @@ An example of subscription to topic `/foo`: ```python def foo_callback(msg): - print msg.data + print(msg.data) # Subscribing. When a message is received in topic /foo, function foo_callback will be invoked. rospy.Subscriber('/foo', String, foo_callback) diff --git a/docs/en/simple_offboard.md b/docs/en/simple_offboard.md index 109c5545..fd372eb8 100644 --- a/docs/en/simple_offboard.md +++ b/docs/en/simple_offboard.md @@ -75,14 +75,14 @@ Displaying drone coordinates `x`, `y` and `z` in the local system of coordinates ```python telemetry = get_telemetry() -print telemetry.x, telemetry.y, telemetry.z +print(telemetry.x, telemetry.y, telemetry.z) ``` Displaying drone altitude relative to [the ArUco map](aruco.md): ```python telemetry = get_telemetry(frame_id='aruco_map') -print telemetry.z +print(telemetry.z) ``` Checking global position availability: @@ -90,9 +90,9 @@ Checking global position availability: ```python import math if not math.isnan(get_telemetry().lat): - print 'Global position is available' + print('Global position is available') else: - print 'No global position' + print('No global position') ``` Output of current telemetry (command line): @@ -307,7 +307,7 @@ Landing the drone: res = land() if res.success: - print 'drone is landing' + print('drone is landing') ``` Landing the drone (command line): diff --git a/docs/en/snippets.md b/docs/en/snippets.md index 90dcd652..b2cf1128 100644 --- a/docs/en/snippets.md +++ b/docs/en/snippets.md @@ -319,7 +319,7 @@ def flip(): rospy.loginfo('finish flip') set_position(x=start.x, y=start.y, z=start.z, yaw=start.yaw) # finish flip -print navigate(z=2, speed=1, frame_id='body', auto_arm=True) # take off +print(navigate(z=2, speed=1, frame_id='body', auto_arm=True)) # take off rospy.sleep(10) rospy.loginfo('flip') diff --git a/docs/en/sonar.md b/docs/en/sonar.md index 48b5e16f..53c42a1a 100644 --- a/docs/en/sonar.md +++ b/docs/en/sonar.md @@ -83,7 +83,7 @@ pi.callback(ECHO, pigpio.FALLING_EDGE, fall) while True: # Reading the distance: - print read_distance() + print(read_distance()) ``` @@ -104,7 +104,7 @@ def read_distance_filtered(): return numpy.median(history) while True: - print read_distance_filtered() + print(read_distance_filtered()) ``` An example of charts of initial and filtered data: diff --git a/docs/ru/aruco_marker.md b/docs/ru/aruco_marker.md index fee1ffe5..bddda97d 100644 --- a/docs/ru/aruco_marker.md +++ b/docs/ru/aruco_marker.md @@ -110,9 +110,9 @@ rospy.init_node('my_node') # ... def markers_callback(msg): - print 'Detected markers:': + print('Detected markers:'): for marker in msg.markers: - print 'Marker: %s' % marker + print('Marker: %s' % marker) # Подписываемся. При получении сообщения в топик aruco_detect/markers будет вызвана функция markers_callback. rospy.Subscriber('aruco_detect/markers', MarkerArray, markers_callback) diff --git a/docs/ru/camera.md b/docs/ru/camera.md index 08ca25e9..9c5a4fd7 100644 --- a/docs/ru/camera.md +++ b/docs/ru/camera.md @@ -140,7 +140,7 @@ def image_callback(data): (x, y, w, h) = barcode.rect xc = x + w/2 yc = y + h/2 - print ("Found {} with data {} with center at x={}, y={}".format(b_type, b_data, xc, yc)) + print("Found {} with data {} with center at x={}, y={}".format(b_type, b_data, xc, yc)) image_sub = rospy.Subscriber('main_camera/image_raw', Image, image_callback, queue_size=1) diff --git a/docs/ru/cli.md b/docs/ru/cli.md index d8c80196..35ed33df 100644 --- a/docs/ru/cli.md +++ b/docs/ru/cli.md @@ -39,7 +39,7 @@ cat file.py Запустить Python-скрипт `file.py`: ```bash -python file.py +python3 file.py ``` Перезагрузить Raspberry Pi: diff --git a/docs/ru/laser.md b/docs/ru/laser.md index 7b9c7623..ba54374e 100644 --- a/docs/ru/laser.md +++ b/docs/ru/laser.md @@ -59,7 +59,7 @@ rospy.init_node('flight') def range_callback(msg): # Обработка новых данных с дальномера - print 'Rangefinder distance:', msg.range + print('Rangefinder distance:', msg.range) rospy.Subscriber('rangefinder/range', Range, range_callback) diff --git a/docs/ru/migrate22.md b/docs/ru/migrate22.md index 8c3d6493..9e66e8c1 100644 --- a/docs/ru/migrate22.md +++ b/docs/ru/migrate22.md @@ -19,7 +19,7 @@ python3 flight.py Синтаксис языка Python 3 имеет определенные изменения по сравнения со второй версией. Вместо *оператора* `print`: ```python -print 'Clover is the best' +print 'Clover is the best' # this won't work ``` теперь используется *функция* `print`: diff --git a/docs/ru/programming.md b/docs/ru/programming.md index 8e13274c..3777f2a8 100644 --- a/docs/ru/programming.md +++ b/docs/ru/programming.md @@ -34,10 +34,10 @@ > **Info** Для изучения языка программирования Python обращайтесь к [самоучителю](https://pythonworld.ru/samouchitel-python). -После настройки системы позиционирования становится возможным написание скриптов для автономных полетов. Для выполнения скриптов [подключитесь в Raspberry Pi по SSH](ssh.md). Для того, чтобы запустить Python-скрипт, используйте команду `python`: +После настройки системы позиционирования становится возможным написание скриптов для автономных полетов. Для выполнения скриптов [подключитесь в Raspberry Pi по SSH](ssh.md). Для того, чтобы запустить Python-скрипт, используйте команду `python3`: ```bash -python flight.py +python3 flight.py ``` Пример программы для полета (взлет, пролет вперед, посадка): diff --git a/docs/ru/ros.md b/docs/ru/ros.md index 2704603e..ff11c2e8 100644 --- a/docs/ru/ros.md +++ b/docs/ru/ros.md @@ -63,7 +63,7 @@ foo_pub.publish(data='Hello, world!') # публикуем сообщение ```python def foo_callback(msg): - print msg.data + print(msg.data) # Подписываемся. При получении сообщения в топик /foo будет вызвана функция foo_callback. rospy.Subscriber('/foo', String, foo_callback) diff --git a/docs/ru/simple_offboard.md b/docs/ru/simple_offboard.md index f2ef57f2..a535dee2 100644 --- a/docs/ru/simple_offboard.md +++ b/docs/ru/simple_offboard.md @@ -75,14 +75,14 @@ land = rospy.ServiceProxy('land', Trigger) ```python telemetry = get_telemetry() -print telemetry.x, telemetry.y, telemetry.z +print(telemetry.x, telemetry.y, telemetry.z) ``` Вывод высоты коптера относительно [карты ArUco-меток](aruco.md): ```python telemetry = get_telemetry(frame_id='aruco_map') -print telemetry.z +print(telemetry.z) ``` Проверка доступности глобальной позиции: @@ -90,9 +90,9 @@ print telemetry.z ```python import math if not math.isnan(get_telemetry().lat): - print 'Global position is available' + print('Global position is available') else: - print 'No global position' + print('No global position') ``` Вывод текущей телеметрии (командная строка): @@ -307,7 +307,7 @@ set_velocity(vx=0.4, vy=0.0, vz=0, yaw=float('nan'), yaw_rate=0.4, frame_id='bod res = land() if res.success: - print 'Copter is landing' + print('Copter is landing') ``` Посадка коптера (командная строка): diff --git a/docs/ru/snippets.md b/docs/ru/snippets.md index adaabe5d..ec70652a 100644 --- a/docs/ru/snippets.md +++ b/docs/ru/snippets.md @@ -337,7 +337,7 @@ def flip(): rospy.loginfo('finish flip') set_position(x=start.x, y=start.y, z=start.z, yaw=start.yaw) # finish flip -print navigate(z=2, speed=1, frame_id='body', auto_arm=True) # take off +print(navigate(z=2, speed=1, frame_id='body', auto_arm=True)) # take off rospy.sleep(10) rospy.loginfo('flip') diff --git a/docs/ru/sonar.md b/docs/ru/sonar.md index 042530f5..7625fad6 100644 --- a/docs/ru/sonar.md +++ b/docs/ru/sonar.md @@ -83,7 +83,7 @@ pi.callback(ECHO, pigpio.FALLING_EDGE, fall) while True: # Читаем дистанцию: - print read_distance() + print(read_distance()) ``` @@ -104,7 +104,7 @@ def read_distance_filtered(): return numpy.median(history) while True: - print read_distance_filtered() + print(read_distance_filtered()) ``` Пример графиков исходных и отфильтрованных данных: