Webots Programming with python - python-2.7

I am a Student in Newcastle University, currently undergoing my Master's Degree. My final project is a simulation using webots. I have to simulate a mobile robot, using python 2.7 coding. The problem is that I cannot find any documentation on python robot programming and the webots website has no python documentation. Everything in the website is based on C examples except from the names of some commands.
Where can I find python documentation for webots in the internet? Or If anyone has documentation can they provide me with it? It will be very helpful for my project.
Thank you.

The complete Python API of the Webots controller module is described in the sections of this chapter:
https://www.cyberbotics.com/doc/reference/nodes-and-api-functions
For example: https://www.cyberbotics.com/doc/reference/accelerometer?tab=python#wb_accelerometer_enable
In Webots, the Python API is exactly the same as the C++ oriented-object API, and the link with the C API is one-to-one too. So "translating" a Webots controller written in C / C++ to Python is often straight forward.
General instructions about programming a Webots controller (written for C) are true for Python too: https://www.cyberbotics.com/doc/guide/controller-programming
Webots contains several Python examples, including:
$WEBOTS_HOME/resources/templates/controllers/template.py (The template used when creating a new Python controller, reading the comments there should help you.)
$WEBOTS_HOME/projects/languages/python/... (a demo to study showing how to control a robot, communicate between robots, do Supervisor tasks, get the Computer keyboard, etc.)
Note also that all the benchmarks of robotbenchmark are written in Python and are using the Webots API (it could be a very good starting point to perform some of these benchmarks).

Related

How can I control and receive video stream from SITL drone using px4,gazebo and C++ without using ROS?

I want to program a drone to fly with a C++ project using image processing analysis in real-time (using OpenCV). I want to do it with PX4, Gazebo simulator. The final goal is to run the project on a real
drone using Jetson-Nano and Pixhawk drone.
I have 2 main problems.
I can't manage to get the video stream of the px4 drone models without using ROS. I have followed this official guide to install the relevant software (Gazebo, Px4, GCS).
For python we have Drone-kit library to control the drone, but I want to use C++ for my project. what are the alternatives tools instead of the Drone-kit to control drones with C++ and how I can receive the video stream from the gazebo px4 drone?
After that I tried to search for information online for hours and go through the documentations, I could not find a suitable guide or solution.
thanks.
Posting this as an answer after details in the comments made things more clear.
For an application like this ROS should most definitely be used. It comes with a wide range of pre-built packages and tools to enable easy localization and navigation. When looking at UAVs the MoveIt! package is a good place to look. It handles 3D navigation and has a few UAV implementations already. The Hector Quadcopter package is another good option for something like SLAM.

OpenCV as a web service

i am looking into facial recognitions using Local Binary Pattern Histogram have came across OpenCV. Within OpenCV, the Local Binary Pattern Histogram has a function which compares histograms "compareHist". How can i perform this function on a web server?. Is it possible to run OpenCV on a web server? (i am thinking about writing the whole function myself however it is based on multiple custom created classes and its rather troublesome - what language should i use? - this would be my last resort).
OpenCV comes with cv::FaceRecognizer, which includes Eigenfaces, Fisherfaces and Local Binary Patterns Histograms. It comes with a very detailed documentation, please see:
http://docs.opencv.org/trunk/modules/contrib/doc/facerec/index.html
No need to implement it yourself. If you want to do this in another language, then you can easily look up the implementation in the contrib module of OpenCV. I am sure you can get some impression there.
As for the webserver. If you have a real server, then sure you could put OpenCV up there and interface with it. If you want to get something going real quick, have a look at the OpenCV Python bindings for cv::FaceRecognizer. I did a post on the OpenCV QA page just yesterday:
http://answers.opencv.org/question/253/broken-python-bindings-with/?answer=255#post-id-255
However, it's a bit complicated due to an error on my side. There was a bug in the official OpenCV 2.4.2 release, so for the Python bindings to work you'll need the trunk version. Note, that the source code is now hosted with git, so you can get it with:
git clone git://code.opencv.org/opencv.git
for example. Then if you are in Linux, you can follow this tutorial on how to install OpenCV:
http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html
or if you are in Windows, then:
http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html
might help. Make sure you have python-dev and python-numpy installed, so the Python bindings are compiled. If you are in Windows, simply install Python2.7 and NumPy (http://www.numpy.org).
You might be interested in my Guide to Face Recognition with Python also, which is available at:
https://github.com/bytefish/facerecognition_guide
That shows a really lightweight implementation of two algorithms.
Disclaimer I am a founder.
Algorithmia provides OpenCV as a service through our API.
http://algorithmia.com/users/opencv

C/C++ Python interpreter

What I'm trying to do is write an app in C/C++ which will allow users to enter a Python script, which the app will then interpret & run. The aforementioned script will have a separate API that I'll implement in C, then expose to the user.
Is there a way to do this? I've searched on Google, but I've only found ways to create 'extensions' and not actual interpreters (like Lua allows).
Documentation about Embedding Python in Another Application says:
The previous chapters discussed how to extend Python, that is, how to extend the functionality of Python by attaching a library of C functions to it. It is also possible to do it the other way around: enrich your C/C++ application by embedding Python in it. Embedding provides your application with the ability to implement some of the functionality of your application in Python rather than C or C++. This can be used for many purposes; one example would be to allow users to tailor the application to their needs by writing some scripts in Python. You can also use it yourself if some of the functionality can be written in Python more easily.
Look especially into Extending Embedded Python:
Until now, the embedded Python interpreter had no access to functionality from the application itself. The Python API allows this by extending the embedded interpreter. That is, the embedded interpreter gets extended with routines provided by the application.
Just read the docs I referenced and you should be able to implement Python interpreter within your app written in C.
You can do a call from C++ to Python and vice versa using Boost Python
If you're interested I recently implemented embedded Python scripting for C++ from first principles. I created a C++ Python wrapper library called ECS:Python (Embedded C++ Scripting with Python) that allows you to expose object from a C++ application to an embedded Python interpreter for interactive scripting. It's light-weight and very easy to use (and free!).
http://sourceforge.net/projects/ecspython

Embedded Python Module Configuration

I'm looking at adding Python support to my game engine project, with the intent of using it as a scripting language for much of the game logic and world building. I'd like to expose a lot of the C++ code to Python. I've already gone through the relevant documentation on the Python site, and I'm fairly confident that I understand the basic requirements for embedding Python and communicating back and forth between Python and the core engine components.
I'm going to embedding Python into the engine itself, rather than compiling the engine as a Python module, since one of my target platforms is the iPhone.
One question I haven't been able to answer myself is how to introduce structure to the C++ modules. For example, I'd like to be able to do something along the lines of:
from engine.scene import skyobject
import engine.core.platforminfo
Would you just create a single "engine" module, and then add some sort of sub module for scene, core, etc? Or should there be separate modules for each of the exposed components, i.e. defining the skyobject module with the name "engine.scene.skyobject"?
Any insight on this is appreciated.

Is there an easy way to provide a Matlab-based Web App or Web Service?

A colleague and I have spent a few years developing a really cool Matlab application, MDLcompress. Within Matlab, I can type "MDLcompress('filename.txt')" and it will tell me all sorts of really cool stuff about the contents of filename.txt. We'd like to allow other people to use MDLcompress without downloading the code, installing Matlab, etc. Ideally, we'd have a simple web page where they selected a file from their machine, it got uploaded to my workstation (which is already running tomcat for other purposes, if that makes things easier), kicked off a process along the lines of "matlab < MDLcompress.m filename.txt > results.txt" and then displayed results.txt in their browser or showed a link to let them download it.
Trouble is, my Matlab skills far exceed my web skills. Google has 100 generic tutorials, but nothing as simple as I want, at least not specific to Matlab.
Thanks in advance
If you are mostly proficient in MATLAB you can write web application in MATLAB with MATLAB Web Server
Edit:
Matlab Web Server is discontinued, so it is not for you if you use recent version of Matlab. May be this tutorial will help to create CGI module from Matlab code.
A possible way is to compile the matlab code into C,
and then make the C file into an apache module, and use an apache server.
I have no idea how complicated this is, but it may work.
Based on the tags, I assume you're trying to deploy to Tomcat or similar. The most straightforward way to do this is to use MATLAB Builder JA to create a Java wrapper for your code, then use the standard tools to deploy the Java as a web service.
If you can afford to lose some of Matlab's more powerful proprietary features, there are several open-source numerical computation engines that use syntax mostly compatible with that of Matlab. One of the most mature of these is GNU Octave.
There are several examples of online Octave interfaces. Octave Online is a new interface that supports a live prompt and an online editor. I am a member of the team developing Octave Online. You can find more examples of online Octave interfaces on the Octave wiki. The Octave mailing list is a good resource for prior online Octave projects.
We have developed a toolbox called Modelit Webserver Toolbox that should allow you to do this. We use this ourselves to run a Routing algorithm implemented in Matlab for an online route planner (the link is on our website). You can use the toolbox in conjunction with Tomcat and Matlab (2006b and up) or a compiled Matlab executable. The toolbox also provides a mechanism to run several jobs in parallel.