Club-spaniego

From jderobot
Jump to: navigation, search

Project[edit]

The main purpose of the project is to program educational robots that use Arduino microprocessors with Python. We have developed PyOnArduino to achieve this target. PyOnArduino comes with a library to develop code on Python that can be compiled an uploaded to an Arduino board with just one command line. PyOnArduino gives support for the main Python elements, the ones used to code the educational robots. Support for three different robots is given: mBot, Complubot (Arduino Robot) and SergioRobot (educational project). There was no previous work done on this project, so we started working on it as part of Google Summer of Code 2018 program.

State of the art[edit]

There is a project on a compiler from Python to C++ called Pyxie. This project aims to help developing on small micros that can’t host a Python runtime. This is a good approach to the idea we are after because it’s focus on developing a compiler that will be used on small devices, like an Arduino micropocessor. Another project that is worth mentioning is Cython. Cython is a programming language based on Python and C/C++ that gives you the possibility of writing C extensions for Python. The source code you code using Cython gets translated into optimized C/C++ code and is then compiled as a Python module. Pyrex is somehow a similar project. It’s another language based on Python that aims to help developing Python extension modules. Cython is more open than Pyrex to extensions and is already more advanced in development. This two projects run parallel. LLVM umbrella project is a project to take into account here, as it covers a great part of what we want to do.

Repositories[edit]

People[edit]

  • Sergio Paniego (sergiopaniegoblanco [AT] gmail.com)
  • Jose María Cañas (jmplaza [AT] gsyc.es)
  • Luis Roberto Morales
  • Gorka Guardiola

Supported robots[edit]

Development[edit]

Phase 3[edit]

Week 12 [30/07 - 06/08][edit]

During this final week we focused on showing the work done until now with different examples. Translator's global variables were moved to a different file to make it easier to understand for someone browsing the code and to make it easier to change those variables. Translator also suffer a major refactor to clean it up and make it extensible in the future easily and mBot tests were added. The following table shows supported python functionality.

Feature Supported
  • Variable Declaration
  • SUPPORTED
  • Function definition
  • SUPPORTED
  • Operators
  • + - / * ^ %
  • Comparators
  • < <= >= == !=
  • Logic operators
  • and or is not
  • Loops
  • while for(future proposal)
  • sleep()
  • SUPPORTED
  • Boolean operations
  • And Or
  • Pass
  • SUPPORTED
  • Arrays
  • Future proposal
  • Tuples
  • Future proposal
  • Range
  • Future proposal

Support for different robot architectures given. This means that starting on this week, a file with the configuration sensor/port can be added on the command line statement. Examples of how this works can be found on the README.md.

We implemented a line follow script and we proved that the same code running on Complubot and mBot has the same behaviour. This means that the same line follow code can be used on any robot and the behaviour should be the same. An example of how this works can be watched on the following video.

  • Line follow same code for Complubot and mBot

Apart form that example, more examples were made for mBot, showing the different possibilities we have when implementing for this robot. The different examples can be watched on the following videos.

  • Light sensor
  • Draw text on the screen
  • Show time on the screen
  • Buzzer test
  • Button test


Week 11 [23/07 - 29/07][edit]

mBot support was upgraded during this week. Full support for the basic architecture was completed. This support will be extended soon.

String are used now as dynamic variables. More tests were also added during this week and a better emergency behaviour was implemented. mBot plays a SOS signal when something is wrong and then stops.

Updated table of supported mBot behaviour:

Sensor Supported
  • Ultrasonic sensors
  • SUPPORTED
  • Light sensor
  • SUPPORTED
  • Button
  • SUPPORTED
  • External screen
  • SUPPORTED
  • Buzzer
  • SUPPORTED
  • Infrared sensors
  • SUPPORTED

Week 10 [16/07 - 22/07][edit]

During this week, a stop function was implemented for each architecture. This means that when an error happens, the system performs a unique error behaviour, so the user can understand that something strange is going on.

Complubot shows this error writing on the screen the word "ERROR!" an stopping the system. SergioRobot turns its leds on an off continuously, meaning that an error occurred.

Apart from this, halduino support for mBot was started, bringing support to a new robot starting this week. To start off with the robot, we studied the examples given by the official documentation and played around with mBlock. An error function was also developed for mBot, turning on and off the leds making a sequence showing that an error occurred. New tests videos below.

Sensor Supported
  • RGB LEDs
  • SUPPORTED
  • Engines
  • SUPPORTED
  • LEDs sequence
  • Hit and rotate


Week 9 [09/07 - 15/07][edit]

Starting this week, variables are now a dynamic type. The variables have now a type and a value. The purpose of this implementation is to check the variables types when they are used on Arduino, because on Python variable’s type can change over time.

There is a new robot in the family, mBot. Support for this robot will be available soon.

New tests videos were also recorded:

  • Hit and rotate
  • Line-Follow
  • Screen write test
  • Beep test
  • Melody test

Phase 2[edit]

Week 8 [02/07 - 08/07][edit]

During this week, support to more Python features was added, giving support to and and/or expressions and keeping on improving the translation on edge case. Support for Linux and Windows operative systems on the compilation and upload was revised and upgraded, giving fully support for Linux and improving it on Windows.

Development of tests started. Starting this week there are tests that fully covert the different Python features on the translator and also tests that covert the SergioRobot examples and Complubot examples was added. We can now check if anything was broken during development.

Feature Comments
  • And / or statements
  • SUPPORTED

Week 7 [25/06 - 01/07][edit]

Starting this week, there is no need to use the Arduino IDE, which previously was compulsory. Compilation and upload from the command line supported. This means that with only one command, the code gets transformed, compiled and uploaded to the board.

Support improved for Complubot. Screen support to write on it with just one function and also support to emit sound and beep also with just one function. Line Follow example written without using Arduino Robot's library but instead actuators and receivers.

Sensor Supported
  • Writing on Screen
  • SUPPORTED
  • Emit Sound
  • SUPPORTED
  • Emit beeps
  • SUPPORTED

We can see how it works on the following video tests:

  • Line-Follow test using actuators and receivers on the robot
  • Screen write test
  • Beep test
  • Sound test


Week 6 [18/06 - 24/06][edit]

Translator code refactored to improve future extension and the ease to make changes over it. Changes based on the Visitor pattern. This pattern is defined as follow: Represent an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. The translator visits the nodes in the tree one by one, calling the specific visitor method based on the type of the node, so it controls every type of node that comes in.

Apart from refactor the code, modification in the wiki to revert the order of how the weeks are show. Starting on this week, the closer week appears on first position and the oldest one down in the last position.

Week 5 [11/06 - 17/06][edit]

New robot added to the project, Complubot. PyOnArduino starts to give support to this new robot. To start off, we want to have the same functionality we already have on the previous example robot. PyOnAduino support for the same sensors we have

Sensor Supported
  • Engines
  • SUPPORTED
  • Ultrasound sensor
  • SUPPORTED
  • Infrared sensor
  • SUPPORTED

We can see how it works on the following video tests:

  • Stop and Go test
  • Hit and Rotate test
  • Line Follow test

Improvements on the Translator itself during the week too.

  • Parentheses recognition added
  • Arrays support
  • Negative numbers support
  • Miscellaneous improvements like better setup support and translator refactor

Phase 1[edit]

Week 4 [04/06 - 10/06][edit]

First target for this week is giving format to Halduino. Completed dividing the Halduino directory in two files, halduino.py and haluino.ino. The first one holds the Python API you can call when building applications. The second one is the translation in Arduino that gets done when you call the API functions. This translation is done by the translator.

More python functionality support added(listed below). The functions accept an unlimited number of parameters. This parameters need to specify its type on the declaration, to make it easier for the translator to understand them. Operators are also supported by limited to operations without parentheses by now. Loops are partly supported. Python’s sleep API call gets translated to delay directly. If and while statements are supported as well.


Feature Limitations/Comments
  • Variable declaration
  • Working on giving suuport to integer, boolean, float and double types.
  • Function definition with return type
  • Argument types must be added on class definition. If no return type is provided, void is expected.
  • Operators
  • + - / * ^ %
  • Loops
  • for / while
  • sleep()
  • supported
  • If
  • If / elif / else


  • Tuples
  • Future work

The following Youtube video shows an example of how the system works. On this example, we take the StopNGo.py file and get the Arduino translation. We then upload the translated file to the Arduino board and it works as expected.

The front ultrasonic sensors get the measurement of the distance to an obstacle. If this distance is lower than 10cm, the engines are stopped, being on otherwise.

Week 3 [28/05 - 03/06][edit]

Stop&Go example completed and added to the repository. Halduino API created. This API collects the functions that are available to the user when developing an application that will be translated. The repository directory set to suffer a reorganization to divide the project into examples, the HALduino API and the translator itself. The example directory will hold the different applications over halduino.py. The HALduino directory will contain both the ino release of the library and the halduino.py file with the API that the users will use for their applications. Finally the translator directory will include the translator itself

Week 2 [21/05 - 27/05][edit]

Beginning of the development of the actual translator, named PyOnArduino[*], whose repository is linked above. The first target was to make a version that could translate our Stop&Go[*] application that controled the car movement on Python to a functional Arduino version.

This translator takes the Stop&Go code, translates it and stores it on an output file[*]. Copying this file directly on the Arduino IDE, it can be compiled and uploaded to the board without issues.

The code has a kind of fixed structure on this point, so the translator can understand it. This structure implies having Python code divided, having a first part for variables, then the functions and finally a While structure. This While structure is the equivalent to the loop statement on the Arduino code.

Week 1 [14/05 - 20/05][edit]

Both apps on Python and Arduino with the same functionality, so we can get an insight on how the translation would look like. The Python app has two functions. One gets the ultrasonic sensor measurement and the other sets the engines to go forward or backward. This functionality is faked and it doesn't really work on an hypothetical Arduino structure. The ultrasonic sensors measurements are read from keyboard input until it gets less than 10 cm and them stops listening and says that it has stopped. The function that set the engines outputs the direction given, either forward or backward.

The Arduino app has exactly the same functionality, but it runs on a real Arduino environment, an small car with an Arduino UNO built-in. The Arduino boards reads the ultrasonic sensor measurement and calculates the distance to the obstacle. It the distance is lower than 10 cm, the second function is called, the one that sets the engines and it turns them off. Once the ultrasonic sensor reading is more than 10cm, the engines are turned on again. To get a better understanding you can watch the following video that shows how the Arduino program works.

After develop this apps, we have a better understanding of how the same functionality is written in the different systems and we can better understand how would we do the translation from Python to Arduino directly. A well-known project that can helps us is LLVM but this project is really vast, so we decided to explore something more straight forward. Python comes with a built-in library called ast, that helps us processing and modifying abstract syntax trees. This library can be really helpful seems it decompose the Python code into more basic and smaller nodes. We wrote a small post on this topic: Abstract Syntax Trees in Python