Difference between revisions of "MYRAbot's arm control (bioloid+arduino)"

From robotica.unileon.es
Jump to: navigation, search
(Creating a package for our programs)
(First program (To whole power))
Line 86: Line 86:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
We must add to the file "CMakeLists.txt" the lines indicated below in order to compile the program and send to [http://www.arduino.cc arduino] board:
  
 +
<syntaxhighlight lang=cmake>set(FIRMWARE_NAME potencia)
  
<!--
+
set(${FIRMWARE_NAME}_BOARD MODELO_NUESTRA_PLACA)  # Modelo placa arduino
 +
set(${FIRMWARE_NAME}_SRCS src/potencia.cpp )
 +
set(${FIRMWARE_NAME}_PORT /dev/ttyACM0)            # Puerto serie de subida
 +
generate_ros_firmware(${FIRMWARE_NAME})</syntaxhighlight>
  
  
===Primer programa (A toda potencia)===
 
  
El primer programa que vamos a realizar crea un nodo llamado “potencia” que publica un ''topic'' llamado “cifra” y está suscrito a un ''topic'' llamado “resultado”. Cuando se publique un número en el ''topic'' “cifra” lo multiplicará por si mismo y publicará el resultado en el ''topic'' “resultado”. El código del programa es el siguiente:
+
<!--
<syntaxhighlight lang=cpp>
 
#include <ros.h>
 
#include <std_msgs/Int16.h>
 
  
ros::NodeHandle nh;
 
int pot;
 
  
void potencia( const std_msgs::Int16& cifra){
 
 
::pot = cifra.data*cifra.data;
 
}
 
 
ros::Subscriber<std_msgs::Int16> sub("cifra", &potencia );
 
std_msgs::Int16 res;
 
 
ros::Publisher pub("resultado", &res);
 
 
void setup()
 
{
 
  nh.initNode();
 
  nh.subscribe(sub); 
 
  nh.advertise(pub);
 
}
 
 
void loop()
 
{
 
  res.data = ::pot;
 
  pub.publish( &res );
 
  nh.spinOnce();
 
  delay(1000);
 
}
 
</syntaxhighlight>
 
Para su compilación y envio a la placa [http://www.arduino.cc arduino] es necesario añadir al archivo CmakeLists.txt las siguientes líneas:
 
 
<syntaxhighlight lang=cmake>set(FIRMWARE_NAME potencia)
 
 
set(${FIRMWARE_NAME}_BOARD MODELO_NUESTRA_PLACA)  # Modelo placa arduino
 
set(${FIRMWARE_NAME}_SRCS src/potencia.cpp )
 
set(${FIRMWARE_NAME}_PORT /dev/ttyACM0)            # Puerto serie de subida
 
generate_ros_firmware(${FIRMWARE_NAME})</syntaxhighlight>
 
  
 
Donde se indica el nombre del programa, tipo de placa [http://www.arduino.cc arduino] (uno, atmega328 o mega2560), nombre y ubicación del archivo y puerto serie del PC empleado para la comunicación con la placa. Deberemos ejecutar los siguientes comandos en un terminal:
 
Donde se indica el nombre del programa, tipo de placa [http://www.arduino.cc arduino] (uno, atmega328 o mega2560), nombre y ubicación del archivo y puerto serie del PC empleado para la comunicación con la placa. Deberemos ejecutar los siguientes comandos en un terminal:

Revision as of 17:24, 24 December 2013

< go back to main

Bioloid arm

The arm that we will use is that Carlos Rodríguez Hernández developed in the project MYRA Robot: Hardware Update . The main components are:

Photograph of Bioloid arm.
  • Arduino mega 2560 board.
  • 74LS241 chip (tree-state Buffer).
  • Voltage regulator circuit.
  • 5 serial servo motors Dynamixel AX-12A.
  • Mounting components of Bioloid kit.
  • Parts made for the gripper and to fix to MYRAbot.

Arduino IDE and rosserial

For the communication among arduino and ROS, we install arduino IDE and rosserial (package de ROS which include the package rosserial_arduino with the libraries for arduino. We will start to installing arduino IDE, for this, we will execute the next commands in a terminal:

sudo apt-get update
sudo apt-get install arduino arduino-core

When the installation of arduino software ends, we will install the ROS package. For this, we will execute the next command in a terminal:

sudo apt-get install ros-ROS_DISTRO-rosserial

When we will have installed arduino IDE and the stack rosserial, we must copy the libraries for the package rosserial_arduino to the sketchbook of arduino. For this, we will execute the next commands in a terminal:

roscd rosserial_arduino/libraries
cp -r ros_lib /home/”SESSION_NAME”/sketchbook/libraries/ros_lib

Creating a package for our programs

Previously, we must have created a workspace for our ROS distribution. We will create a package in order to compile and send our programs to arduino board. We will make a package named "arduino_fer" with the the necessary dependences for our programs, for this, we will execute the next commands in a terminal:

cd ~/ros_workspace
roscreate-pkg arduino_fer rosserial_arduino std_msgs

We must change the content of the file "CMakeLists.txt" of our package for the next lines:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_find_ros_package(rosserial_arduino)
include(${rosserial_arduino_PACKAGE_PATH}/cmake_scripts/rosserial.cmake)

We will execute the next commands in a terminal to finalize the creation of the package:

roscd arduino_fer
cmake .

First program (To whole power)

We will make the first program that publishes a topic named "cifra" and subscribe a topic named "resultado". When we publish a number in the topic "cifra" the program multiplies the number by itself and publishes the result in the topic "resultado". The code of the program is shown below:

#include <ros.h> 
#include <std_msgs/Int16.h> 

ros::NodeHandle nh; 
int pot; 

void potencia( const std_msgs::Int16& cifra){ 

::pot = cifra.data*cifra.data; 
} 

ros::Subscriber<std_msgs::Int16> sub("cifra", &potencia ); 
std_msgs::Int16 res; 

ros::Publisher pub("resultado", &res); 

void setup() 
{ 
  nh.initNode(); 
  nh.subscribe(sub);  
  nh.advertise(pub); 
} 

void loop() 
{ 
  res.data = ::pot; 
  pub.publish( &res ); 
  nh.spinOnce(); 
  delay(1000); 
}

We must add to the file "CMakeLists.txt" the lines indicated below in order to compile the program and send to arduino board:

set(FIRMWARE_NAME potencia)

set(${FIRMWARE_NAME}_BOARD MODELO_NUESTRA_PLACA)   # Modelo placa arduino
set(${FIRMWARE_NAME}_SRCS src/potencia.cpp )
set(${FIRMWARE_NAME}_PORT /dev/ttyACM0)            # Puerto serie de subida
generate_ros_firmware(${FIRMWARE_NAME})



< go back to main