User Tools

Site Tools


en:libschsat-py

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
en:libschsat-py [2017/12/03 16:30]
writer [Interface Transmitter]
en:libschsat-py [2018/01/25 17:18]
ashley i
Line 3: Line 3:
 [WORK IN PROGRESS] [WORK IN PROGRESS]
  
-Starting with version 1.02 the standard library includes support for the [[https://​www.python.org|Python]] programming language. If you use this version of the library or more recent versions, then you can access the interface functions of the standard library using one of the most popular programming languages. ((The standard library is implemented in the low-level programming language С.))+Starting with version 1.02the standard library includes support for the [[https://​www.python.org|Python]] programming language. If you use this version of the library or more recent versions, then you can access the interface functions of the standard library using one of the most popular programming languages. ((The standard library is implemented in the low-level programming language С.))
  
 ===== Fast start ===== ===== Fast start =====
Line 12: Line 12:
   - Implement a function named ''​control''​ in Python ​ ((The function ''​ control () ''​ is the entry point to your Python code, look at it as a function ''​main()''​.))   - Implement a function named ''​control''​ in Python ​ ((The function ''​ control () ''​ is the entry point to your Python code, look at it as a function ''​main()''​.))
  
-An example of a simple Python project+Here is an example of a simple Python project:
  
 <file python hello.py>​ <file python hello.py>​
Line 22: Line 22:
 ===== Interface Functions ===== ===== Interface Functions =====
  
-Describing ​the interface functions we will indicate:+In describing ​the interface functionswe will indicate:
  
   * function name (function name is unique)   * function name (function name is unique)
Line 33: Line 33:
  hyro_request_reset(num) -> err  hyro_request_reset(num) -> err
  
-In the example above the interface named ''​hyro_request_reset''​ is shown. ''​hyro_request_reset''​is the name of the Python function. ​Function ​takes one argument ''​num''​ (sensor number) and returns a single value -- ''​err''​ (error code).+In the example abovethe interface named ''​hyro_request_reset''​ is shown. ''​hyro_request_reset''​is the name of the Python function. ​The function ​takes one argument ''​num''​ (sensor number) and returns a single value -- ''​err''​ (error code).
  
-Most interface functions expect that the first argument is the device number (number of sensor or number of actuating mechanism ​of this type). Usually device number is a number from ''​0''​ to ''​3''​. Also, most interface functions return the value of called function execution status (return an error code). In the example above, this fact is marked as a pair of characters --> ''​err''​.+Most interface functions expect that the first argument is the device number (number of sensor or number of actuating mechanism). Usually, the device number is a number from ''​0''​ to ''​3''​. Also, most interface functions return the value of the called function'​s ​execution status (return an error code). In the example above, this is marked as a pair of characters --> ''​err''​.
  
-Using interface functions it is important to analyze the returned error code (the value of ''​err''​). If the called function ​is finished ​without error, it returns zero ''​(0)'', ​otherwise ​a non-zero value. ​An example of processing the value returned by the function:+When using interface functionsit is important to analyze the returned error code (the value of ''​err''​). If the called function ​was completed ​without error, it returns zero ''​(0)''​. Otherwiseit will return ​a non-zero value. ​Below is ann example of processing the value returned by the function:
  
 <code python> <code python>
Line 45: Line 45:
 </​code>​ </​code>​
  
-Interface functions often have names  ''​interface_request_reset'',​ ''​interface_get_state'',​ ''​interface_turn_on()''​ and ''​interface_turn_off'',​ where ''​interface'' ​-- an interface ​name.+Interface functions often have functions called ​ ''​interface_request_reset'',​ ''​interface_get_state'',​ ''​interface_turn_on()''​ and ''​interface_turn_off'',​ where ''​interface'' ​is the name of the interface.
  
-These functions are generally used as followsExample for the ''​hyro''​ interface+These functions are generally used as follows ​(Example for the ''​hyro''​ interface): 
  
 <code python> <code python>
Line 87: Line 87:
 ==== Interface Battery ==== ==== Interface Battery ====
  
-These interface functions allow you to determine the state of the virtual battery ([[power_subsys|PSS]]). These functions ​don’t ​take any arguments. Each of the functions returns a parameter as a single-precision floating-point number.+These interface functions allow you to determine the state of the virtual battery ([[power_subsys|PSS]]). These functions ​do not take any arguments. Each of the functions returns a parameter as a single-precision floating-point number.
  
  battery_get_charge() -> value  battery_get_charge() -> value
Line 111: Line 111:
  camera_take_photo(frame) -> err  camera_take_photo(frame) -> err
  
-The function ''​camera_take_photo''​ takes a photo with the number specified with the argument ''​frame''​. Usually, you number the pictures with numbers from ''​0''​ to ''​9''​. The function returns ''​0''​ if the action is successful, otherwise the value is different from zero.+The function ''​camera_take_photo''​ takes a photo with the number specified with the argument ''​frame''​. Usually, you number the pictures with numbers from ''​0''​ to ''​9''​. The function returns ''​0''​ if the action is successful, otherwise the value is non-zero.
  
  camera_turn_off() -> err  camera_turn_off() -> err
Line 178: Line 178:
 ==== Interface Hyro ==== ==== Interface Hyro ====
  
-These interface functions are used to work with the angular velocity sensor ([[w_subsys|AVS]]). ​Argument ​''​num''​ is a sensor number (it can take varies ​from ''​0''​ to ''​3''​).+These interface functions are used to work with the angular velocity sensor ([[w_subsys|AVS]]). ​The argument ​''​num''​ is a sensor number (it can take values ​from ''​0''​ to ''​3''​).
  
  hyro_get_state(num) -> ready  hyro_get_state(num) -> ready
Line 202: Line 202:
 ==== Interface Magnetometer ==== ==== Interface Magnetometer ====
  
-These interface functions are designed to work with a [[mag_subsys|magnetometer]]. The argument ''​num''​ is number of the magnetometer (it can take values from ''​0''​ to ''​3''​).+These interface functions are designed to work with a [[mag_subsys|magnetometer]]. The argument ''​num''​ is the number of the magnetometer (it can take values from ''​0''​ to ''​3''​).
  
  magnetometer_get_state(num) -> ready  magnetometer_get_state(num) -> ready
Line 225: Line 225:
 ==== Interface Motor ==== ==== Interface Motor ====
  
-These interface functions are designed to control [[wheel_subsys|flywheels]]. ​Argument ​''​num''​ is the number of the flywheel (it can take values from ''​0''​ to ''​3''​).+These interface functions are designed to control [[wheel_subsys|flywheels]]. ​The argument ​''​num''​ is the number of the flywheel (it can take values from ''​0''​ to ''​3''​).
  
  motor_get_state(num) -> ready  motor_get_state(num) -> ready
Line 249: Line 249:
 </​code>​ </​code>​
  
-> **IMPORTANT**The set value of speed (the second argument of the function) and the return value of the speed (the second element of the return value list) must be close in value and sign (speed direction). If the function returns an error code other than ''​0'',​ then you can not trust the return value of the speed!+> **IMPORTANT**The set value of speed (the second argument of the function) and the return value of the speed (the second element of the return value list) must be close in value and sign (speed direction). If the function returns an error code other than ''​0'',​ then you cannot ​trust the return value of the speed!
  
  motor_turn_off(num) -> err  motor_turn_off(num) -> err
Line 318: Line 318:
 ==== Interface Transceiver ==== ==== Interface Transceiver ====
  
-These interface functions control sixteen [[uhf_tx_subsys|telemetry transmitters]];​ are used to transmit and receive data arrays (telemetry). ​Argument ​''​num''​ is the number of the telemetry transmitter (it can take values from ''​0''​ to ''​15''​).+These interface functions control sixteen [[uhf_tx_subsys|telemetry transmitters]]; ​they are used to transmit and receive data arrays (telemetry). ​The ''​num'' ​argument ​is the number of the telemetry transmitter (it can take values from ''​0''​ to ''​15''​).
  
  transceiver_get_state(num) -> ready  transceiver_get_state(num) -> ready
Line 334: Line 334:
  transceiver_send(txnum,​ rxnum, data) -> err  transceiver_send(txnum,​ rxnum, data) -> err
  
-The function ''​transceiver_send''​ transfers ''​data''​ from the transmitter number ''​txnum''​ to the receiver number ''​rxnum''​. In case of successful data translation the function returns ''​0''​.+The function ''​transceiver_send''​ transfers ''​data''​ from the transmitter number ''​txnum''​ to the receiver number ''​rxnum''​. In the case of successful data translationthe function returns ''​0''​.
  
 <code python> <code python>
Line 352: Line 352:
 ==== Interface Transmitter ​ ==== ==== Interface Transmitter ​ ====
  
-These interface functions control [[hf_tx_subsys|the HF transmitters]]. ​Transmission ​of pre-captured and saved photos is carried out using the function ''​transmitter_transmit_photo''​. ​Argument ​''​num''​ is the number of the HF transmitter (it can take values from ''​0''​ to ''​3''​).+These interface functions control [[hf_tx_subsys|the HF transmitters]]. ​The transmission ​of pre-captured and saved photos is carried out using the function ''​transmitter_transmit_photo''​. ​The argument ​''​num''​ is the number of the HF transmitter (it can take values from ''​0''​ to ''​3''​).
  
  transmitter_get_state(num) -> ready  transmitter_get_state(num) -> ready
Line 364: Line 364:
  transmitter_transmit_photo(num,​ frame) -> err  transmitter_transmit_photo(num,​ frame) -> err
  
-The function ''​transmitter_transmit_photo''​ transmits a photo with number ''​frame'' ​using the HF transmitter with number ''​num''​. If the photo is successfully transmitted,​ the function returns ''​0''​.+The function ''​transmitter_transmit_photo''​ transmits a photo with the "frame" number ​using the HF transmitter with number ''​num''​. If the photo is successfully transmitted,​ the function returns ''​0''​.
  
  transmitter_turn_off(num) -> err  transmitter_turn_off(num) -> err
Line 377: Line 377:
  
 ==== Runtime Environment ==== ==== Runtime Environment ====
-Projects ​on Python as well as on C, you can prepare ​using the interface of [[gui_interface|the programming environment]] based on the editor ​[[https://​notepad-plus-plus.org|''​notepad++''​]]. ​Zip-archive prepared in the programming environment contains an automatically generated Python script for execution. This script includes the content ​of your file. Schematically and very simplistically the script ​is about the following+Projects ​in Python as well as projects in C, can be prepared ​using the interface of [[gui_interface|the programming environment]] based on the [[https://​notepad-plus-plus.org|''​notepad++''​]] ​editorA zip-archiveprepared in the programming environmentcontains an automatically generated Python script for execution. This script includes the contents ​of your file. Schematicallyand very simplisticallythe script ​can be written as follows:
  
 <code python> <code python>
Line 389: Line 389:
 </​code>​ </​code>​
  
-Now it becomes ​clear why we can use the ''​sleep''​ function from the ''​time''​ module in our programs. It'​s ​also obvious that your code can import additional Python modules, for example+Now it should become ​clear why we can use the ''​sleep''​ function from the ''​time''​ module in our programs. It is also obvious that your code can import additional Python modules, for example:
  
 <code python> <code python>
Line 406: Line 406:
 </​code>​ </​code>​
  
-return an unsigned integer - device readiness flag. If the return value is ''​1'',​ it means that the device is ready and you can work with the device (interface). For example, you can subtract data from the sensor or turn on the actuating mechanism. If the function returned ''​0'',​ it means that the device was not prepared for operation, you did not activate the interface (did not call the corresponding ''​interface_turn_on''​ function).+return an unsigned integer - the device readiness flag. If the return value is ''​1'',​ it means that the device is ready and you can work with the device (interface). For example, you can subtract data from the sensor or turn on the actuator. If the function returned ''​0'',​ it means that the device was not prepared for operation, ​and you did not activate the interface (did not call the corresponding ''​interface_turn_on''​ function).
  
-> **ATTENTION**: ​the readiness of the device only means that you can start using the device. The ready flag does not mean that the functions called later will return valid data or the device will accept commands. Be sure to check the error codes returned by the interface functions!+> **ATTENTION**: ​The readiness of the device only means that you can start using the device. The ready flag does not mean that the functions called later will return valid data or that the device will accept commands. Be sure to check the error codes returned by the interface functions!
  
 Interface functions of the form Interface functions of the form
Line 420: Line 420:
  
  
-The //"​interface error"//​ code is returned when the interface function is misused, for example, a non-existent device number is specifiedor when noises ​occurred on the data bus and data could not be read.+The //"​interface error"//​ code is returned when the interface function is misused, for example, ​when a non-existent device number is specified or when noise occurred on the data bus and data could not be read.
  
-The //"​access error"//​ code is returned when you tried to request data from a device that is not ready yet, for example, ​accessed ​a device that was not previously enabled.+The //"​access error"//​ code is returned when you try to request data from a device that is not yet ready, for example, ​accessing ​a device that was not previously enabled.
  
 If you want to know the type of error that occurred, simply print the ''​err''​ variable: If you want to know the type of error that occurred, simply print the ''​err''​ variable:
en/libschsat-py.txt · Last modified: 2018/10/10 11:59 by golikov