User Tools

Site Tools


en:examples-py

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
en:examples-py [2017/11/26 21:00]
writer
en:examples-py [2017/11/26 21:23]
writer
Line 8: Line 8:
 from schsat import * from schsat import *
 </​code>​ </​code>​
-in Python, the names of libraries and modules are called without the extension .py, the '​*'​ in this context means the import of all fields. All functions for controlling the construction set must be called inside the ''​control ()''​ function in the text of your program. Example:+in Python, the names of libraries and modules are called without the extension .py, the '​*'​ in this context means the import of all fields. All functions for controlling the construction set must be called inside the ''​control()''​ function in the text of your program. Example:
 <code python> <code python>
 def control(): def control():
Line 20: Line 20:
 def take_frame(frame):​ def take_frame(frame):​
     camera_turn_on()     camera_turn_on()
-    sleep(2) ​                   # on the camera and wait for the device to load+    sleep(2) ​                   # turn on the camera and wait for the device to load
     ready = camera_get_state() ​         # Check if the camera is ready     ready = camera_get_state() ​         # Check if the camera is ready
     if ready:     if ready:
Line 43: Line 43:
 <code python> <code python>
 # Function - wrapper for magnetometer_request_raw (num) -> err function # Function - wrapper for magnetometer_request_raw (num) -> err function
-def magn_get(nmg,​ off = True): # nmg - magnetometer number,​variable off - whether to switch off the sensor ​+def magn_get(nmg,​ off = True): # nmg - magnetometer number, variable off - whether to switch off the sensor ​
      # function that works with the sensor checking whether it is on      # function that works with the sensor checking whether it is on
      # and returning the list [0, x_raw, y_raw, z_raw] if it is possible ​      # and returning the list [0, x_raw, y_raw, z_raw] if it is possible ​
      # to get the data, and [1, 0, 0, 0] if an error occurred. ​      # to get the data, and [1, 0, 0, 0] if an error occurred. ​
     if not magnetometer_get_state(nmg):​ # if the sensor is not turned on     if not magnetometer_get_state(nmg):​ # if the sensor is not turned on
-        if magnetometer_turn_on(nmg):​ return [1, 0, 0, 0] # try to turn on +        if magnetometer_turn_on(nmg):​ return [1, 0, 0, 0] # try to turn it on 
-        sleep(0.5) # if the sensor was turned on wait for the loading to be 0.5 seconds+        sleep(0.5) # if the sensor was turned on wait 0.5 seconds ​for the loading ​
     magn_ret = magnetometer_request_raw(nmg) # save the speed value to variable magn_ret     magn_ret = magnetometer_request_raw(nmg) # save the speed value to variable magn_ret
     if magn_ret[0]:​ # if the sensor returned an error message     if magn_ret[0]:​ # if the sensor returned an error message
Line 78: Line 78:
     if not hyro_get_state(nhyr):​ # if the sensor is not turned on     if not hyro_get_state(nhyr):​ # if the sensor is not turned on
         if hyro_turn_on(nhyr):​ return [1, 0, 0, 0] # try to turn on         if hyro_turn_on(nhyr):​ return [1, 0, 0, 0] # try to turn on
-        sleep(0.5) # if the sensor was turned on wait for the loading to be 0.5 seconds+        sleep(0.5) # if the sensor was turned on wait 0.5 seconds ​for the loading ​
     hyro_ret = hyro_request_raw(nhyr) # save the speed value to variable hyro_ret     hyro_ret = hyro_request_raw(nhyr) # save the speed value to variable hyro_ret
     if hyro_ret[0]:​ # if the sensor returned an error message     if hyro_ret[0]:​ # if the sensor returned an error message
Line 118: Line 118:
 </​code>​ </​code>​
  
-**5. Рекомендуемый код для проверки управления маховиком**+**5. Code recommended for checking the flywheel control**
  
 <code python> <code python>
 def motor_check(num):​ def motor_check(num):​
-    if not motor_get_state(num):​ # включен ли мотор +    if not motor_get_state(num):​ # checking if the motor is on 
-        if motor_turn_on(num):​ return 1 # попробовать включитьесли невозможно,​ ошибка +        if motor_turn_on(num):​ return 1 # try to turn onif not possible display the error code 
-        sleep(2) ​                       # ждать включения +        sleep(2) ​                       # wait for device to load 
-    if motor_set_speed(num,​ 1000): return 1 # настроить скорость,​ или вернуть ошибку +    if motor_set_speed(num,​ 1000): return 1 # set the speed or return an error code 
-    sleep(5) ​                               # пять секунд ожидания +    sleep(5) ​                               # five seconds waiting 
-    if motor_set_speed(num,​ 0): return 1    # натсроить скорость,​ или верунть ошибку +    if motor_set_speed(num,​ 0): return 1    # set the speed or return an error code 
-    motor_turn_off(num) ​                    # ​выключить ошибку +    motor_turn_off(num) ​                    # ​turn off 
-основная программа+The main program ​
 def control(): def control():
     res = motor_check(1)     res = motor_check(1)
Line 135: Line 135:
 </​code>​ </​code>​
  
-**6. Рекомендуемый код для проверки передатчика телеметрии**+**6. Сode recommended for checking the telemetry transmitter**
 <code python> <code python>
-Пример функции для передачи любого сообщения,​ переданного как переменная ​msg типа ​str+An example of a function to send any message sent as a msg variable of type str
 def msg_send(msg,​ trn = 1, res = 2, off = True): ​ def msg_send(msg,​ trn = 1, res = 2, off = True): ​
-    # msg - сообщение, trn - номер передатчика, res - номер наземного приемника,  +    # msg - message, trn - transmitter number, res - ground receiver number,  
-    # off - нужно ли выключить передатчик при завершении ​(True - да, False - нет+    # off - whether it is necessary to turn off the transmitter after the program termination ​  
-    if not transceiver_get_state(trn):​ # если передатчик не включенвключить +    # (True - yes, False - no
-        if transceiver_turn_on(trn): ​  # ​попытка включить +    if not transceiver_get_state(trn):​ # if the transmitter is offturn it on 
-            return 1                   # ​если не удалось включитьвернуть код ошибки ​+        if transceiver_turn_on(trn): ​  # ​try to turn on 
-        sleep(0.5) ​                    # ​если нормально принят сигнал о включенииждать ​0.5 сек +            return 1                   # ​if failedreturn error code 
-    if not transceiver_send(res,​ trn, msg): # если не удалось передать сообщение,​ +        sleep(0.5) ​                    # ​if the power-on signal is normally receivedwait 0.5 s 
-        transceiver_turn_off(trn) # выключить передатчик +    if not transceiver_send(res,​ trn, msg): # if the message could not be transmitted 
-        return 1 # вернуть код ошибки +        transceiver_turn_off(trn) # turn off the transmitter 
-    if off: transceiver_turn_off(trn) ​ # выключить передатчик +        return 1 # return error code 
-    return 0 # вернуть код нормального завершения+    if off: transceiver_turn_off(trn) ​ # turn off the transmitter 
 +    return 0 # return normal completion code
 </​code>​ </​code>​
  
-**7. Рекомендуемый код функции для проверки ВЧ-передатчика**+**7. Сode recommended for checking the HF transmitter**
 <code python> <code python>
 def send_frame(num,​ frame, off = True): def send_frame(num,​ frame, off = True):
-    if not tranmitter_get_state(num):​ # проверка состояния ВЧ-передатчика+    if not tranmitter_get_state(num):​ # check the status of the HF transmitter
         if transmitter_turn_on(num):​ return 1         if transmitter_turn_on(num):​ return 1
         sleep(2)         sleep(2)
-    if transmitter_transmit_photo(num,​ frame): # передаем кадр ​frame +    if transmitter_transmit_photo(num,​ frame): # transmit ​frame "​frame"​ 
-        if off: transmitter_turn_off(name) # допускаем,​ что выключение всегда успешно+        if off: transmitter_turn_off(name) # it is assumed that the shutdown is always successful
-        return 1                           # ​новообще говоряэто может быть не так+        return 1                           # ​butgenerally speakingthis may not be the case
     if off: transmitter_turn_off(1)     if off: transmitter_turn_off(1)
-    return 0 # код нормального завершения+    return 0 # normal completion code
 </​code>​ </​code>​
  
-**8. Рекомендуемый код для работы с батареей ​**+**8. Code recommended for working with battery ​**
 <code python> <code python>
 def battery(): def battery():
-    ah = battery_get_charge() ​                # ​проверяем заряд +    ah = battery_get_charge() ​                # ​check the charge 
-    cc = battery_get_charging_current() ​      # ​ток зарядки +    cc = battery_get_charging_current() ​      # ​charging current 
-    dc = battery_get_discharging_current() ​   # ток разрядки +    dc = battery_get_discharging_current() ​   # discharging current 
-    print '​Ёмкость батареи:​ %g A-H' % ah      # выводим данные+    print '​Ёмкость батареи:​ %g A-H' % ah      # output the data
     print '​Ток заряда:​ %g mA' % cc     print '​Ток заряда:​ %g mA' % cc
     print '​Ток разряда:​ %g mA' % dc      print '​Ток разряда:​ %g mA' % dc 
-    return [ah, cc, dc]                       # ​возвращаем значения+    return [ah, cc, dc]                       # ​return values
 </​code>​ </​code>​
  
en/examples-py.txt · Last modified: 2020/03/25 16:28 (external edit)