Mostrando entradas con la etiqueta Programación. Mostrar todas las entradas
Useful ROS commands
1.- Workspace:
Create and build and empty workspace:
For the examples the workspace is called “catkin_ws”:Create a package:
Go to the source directory of the workspace: cd ~/catkin_ws/src
then create a package catkin_create_pkg [depend1] [depend2] [depend3]
catkin_create_pkg requires that you give it a package_name and optionally a list of dependencies on which that package depends.Example:
catkin_create_pkg turtlebot_controller turtlesim geometry_msgs std_msgs roscpp rospy
The name of the package is "turtlebot_controller" and the dependences are "turtlesim", "geometry_msgs", "std_msgs", "roscpp" and "rospy"
Build the packages in the catkin workspace:
cd ~/catkin_ws
catkin_make
To add the workspace to the ROS environment :
. ~/catkin_ws/devel/setup.bash
2.- Running and see states:
Start using ROS:
roscore
this command is the first thing you should run when using ROS.Run a node of a package:
rosrun [package_name] [node_name]
Displays ROS nodes that are currently running:
rosnode list
/rosout is always presentDisplay more information about a node currently running:
rosnode info [node]
Example: rosnode info /rosout
Displays ROS topics that are currently present:
rostopic list
See the actual messages that are being published on a topic:
rostopic echo [topic]
Get information about ROS topics:
rostopic type [topic]
It will be updated with more commands ...
Create a simple graph in Python and Matlab
Python examples:
With arange (use the form start,end,step):
arange documentation:http://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html#numpy.arange
With linespace
linespace documentation:http://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html
Matlab examples:
Creating a vector of values (form start:step:end)
With linespace
Install Python + OpenCV in Mac OS X Yosemite
1.- Install the prerequisite software:
1.1.- Install MacPorts from:
1.2.- Install Xcode from apple store. Once installed, open Xcode and accept the licence agreement (In this tutorial Xcode 6.4 was used).
1.3.- Install the "Command Line Tools". For this go to the terminal (Applications > Utilities > Terminal) and write:
sudo xcode-select --install
A windows is shown, you need to select "install" and wait until installation is finished.
1.4 Once Command Line Tools are installed, see the xcode instalation path with:
sudo xcode-select -p
In my case this command print:
/Applications/Xcode.app/Contents/Developer
1.5 Then, run the next command:
sudo xcode-select -switch <xcode path>
Where in my case is:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
1.6.- Go to the terminal and update the package index with:
sudo port -v selfupdate
and
sudo port upgrade outdated
and
sudo port upgrade outdated
2.- Install Python and basic packages:
2.1 Install Python with: sudo port install python27
2.2 Select the version of python as:
sudo port select --set python python27
2.3 Install the basic packages of scientific computing (matplotlib and numpy are required for use OpenCV).
sudo port install py27-numpy py27-matplotlib py27-scipy
3.- Install OpenCV
3.1 Install OpenCV with support for Python with:
sudo port install opencv +python27
3.2 To verify that the installation is correct, write in the terminal:
python
The, in the python terminal and write:
import cv2
If no error is shown then the installation was successful.
Note: I'm sorry for my poor grammar!
Cambiar directorio o ruta de la terminal de Python
Para ello se debe escribir en la terminal de python:
import os
Si se desea conocer el directorio actual de trabajo escribir:
os.getcwd()
Para cambiar de directorio simplemente hay que usar la función os.chdir y especificar la ruta del nuevo directorio, por ejemplo en el escritorio en Windows:
os.chdir('C:\\Users\\username\\Desktop')
Donde username es el nombre de usuario.
Agregar código a una entrada en Wordpress.com
Para agregar código con un formato agradable y numerado como:
Simplemente hay que entrar en el modo texto y agregar:
Donde se puede se puede sustituir "python" otro lenguaje de programación soportado. Un ejemplo se muestra en la siguiente imagen.
Para mayor información y ver los lenguajes soportados visitar: https://en.support.wordpress.com/code/posting-source-code/
Simplemente hay que entrar en el modo texto y agregar:
Donde se puede se puede sustituir "python" otro lenguaje de programación soportado. Un ejemplo se muestra en la siguiente imagen.
Para mayor información y ver los lenguajes soportados visitar: https://en.support.wordpress.com/code/posting-source-code/
Ejemplos del uso del ciclo FOR en Python
Introducción:
A continuación se presentan algunos ejemplos del uso del ciclo for en Python.
Para realizar una acción un número n de iteraciones se puede utilizar el siguiente formato:
acciones a repetir
Donde var es la variable que cambiará su valor en cada iteración y lo que esté dentro de range() indica el número de iteraciones del ciclo y la forma en que se incrementan o decrementan los valores en var.
Incremento de la variable:
Para realizar incrementos de 1 en 1 de la variable var de 0 a n -1 se utiliza range(n)
Ejemplo:
# Incremento de 0 a n-1
n = 5
for var in range (n):
print var
Para realizar incrementos a partir de un número deseado se utiliza range (m,n), donde m indica el valor inicial de var.
# Incremento de 0 a n-1
n = 5
for var in range (n):
print var
Para realizar incrementos a partir de un número deseado se utiliza range (m,n), donde m indica el valor inicial de var.
# Incremento de m a n-1
m = 2
n = 5
for var in range (m,n):
print var
El formato range (m,n, k) incrementa la variable var de k en k en lugar de 1 en 1.
Ejemplo:
m = 2
n = 8
k = 2 #incremento
for var in range (2,n,k):
print var
Decremento de la variable:
Para realizar decrementos de n a m+1 se utiliza range (n,m,-1).
# Decremento de n a m+1
n = 5
m = -1
for var in range (n,-1,-1):
print var
Recorrer elementos de una lista:
Además se puede recorrer una lista de valores con el siguiente formato:for var in lista:
acciones a repetir
Ejemplo:
n = 5
lista = ['1',2,3.5,(2,3),[3,5],n]
for var in lista:
print var
Programa gratuito para realizar diagramas de flujo.
El programa ClickCharts es un software completamente gratuito para el desarrollo de diagramas de flujo simples pero adecuados para representar algoritmos gráficamente.
Los diagramas de flujo realizados pueden ser exportados a formatos populares como .jpg, .png y PDF. Además se puede definir la resolución en DPI de las imágenes exportadas. La interfaz que presenta el programa se muestra en la siguiente figura.
Este programa se puede descargar desde página oficial: http://www.nchsoftware.com/chart/
Utilizar sintáxis de LaTeX en Blogger
Por ejemplo:
$\begin{matrix}
\hat{x}_{k}^+ = \hat{x}_{k}^{-} + K_{k}(z_{k} - \hat{x}_k^{-})\\
P_k = (1-K)P^{-}_k
\end{matrix} $
Para ello hay que ir al código HTML una vez se ha escrito la entrada (Figura 1).
![]() |
| Figura 1 |
Una vez se está en el modo HTML escribir al final lo siguiente:
<html>
<head>
<title>MathJax TeX Test Page</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
</script>
</head>
<body>
</body>
</html>
Un ejemplo de como escribir $x=2y$ en una entrada como en la figura 2, se muestra a continuación:
![]() |
| Figura 2 |
$x=2y$<html>
<head>
<title>MathJax TeX Test Page</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
</script>
</head>
<body>
</body>
</html>














