Home >> Electrodomésticos >> Home Audio >> Inicio Audio

Cómo programar un robot: de kit educativo a robot autónomo (ROS 2, Python, Arduino)

Enfoque según nivel y objetivo

NivelPlataforma típicaLenguaje / EntornoComplejidad
Iniciación (8-14 años)LEGO SPIKE Prime, mBot, micro:bit, MakeblockBloques (Scratch), MicroPythonSecuencias, bucles, sensores básicos
Educación secundaria / FP / MakerArduino (Uno, Nano, Mega), ESP32, Raspberry Pi PicoC++ (Arduino IDE), MicroPython, CircuitPythonControl motores, sensores, Bluetooth/WiFi, lógica estados
Universidad / Investigación / ProRobot móvil (TurtleBot, Clearpath, Husky), brazo (UR, Franka, xArm), drones (PX4)ROS 2 (Robot Operating System) — C++ / Python, Gazebo/Isaac SimNavegación SLAM, manipulación, percepción, multi-robot, tiempo real
IndustrialABB, KUKA, FANUC, Yaskawa, Universal RobotsRAPID, KRL, TP, URScript, PolyscopePuntos, trayectorias, I/O, seguridad funcional (ISO 10218)

Paso a paso: Robot móvil autónomo con ROS 2 (ej. TurtleBot 4 / Raspberry Pi 4 + RPLIDAR + Create 3)

1. Hardware base

  • Plataforma móvil diferencial (Create 3, o chasis DIY + 2 motores DC + encoder + driver L298P/TB6612 + LiPo 2S/3S).
  • SBC: Raspberry Pi 4/5 (4-8 GB) o Jetson Orin Nano (IA edge).
  • LiDAR 2D: RPLIDAR A1/A2/S1, LD06, YDLIDAR X4 (360°, 8-12 Hz).
  • Cámara opcional: Raspberry Pi Camera Module 3 / Oak-D (estéreo + IA).
  • IMU: ICM-20948 (integrado en Create 3 / Pi Hat).
  • Batería Li-ion 18650 4S/6S + BMS + regulador 5 V 5 A (UBEC).

2. Software base (Ubuntu 22.04 + ROS 2 Humble / Iron)

  • Imagen Ubuntu Server + ROS 2 preinstalado (TurtleBot 4 image, o `ros2_humble_raspberry_pi_4.img.xz`).
  • Configura red: hostname, SSH, Wi-Fi (Netplan), ROS_DOMAIN_ID único.
  • Instala paquetes robot: `ros-humble-turtlebot4*`, `ros-humble-nav2*`, `ros-humble-slam-toolbox`, `ros-humble-robot-localization`.

3. Bringup (drivers hardware)

  • Create 3: `ros2 launch turtlebot4_bringup standard.launch.py` (publica `/odom`, `/tf`, `/scan`, `/imu`, `/battery_state`; suscribe `/cmd_vel`).
  • LiDAR: `ros2 launch rplidar_ros rplidar.launch.py` (frame `laser_link`).
  • Transforms estáticos (URDF / xacro): define `base_link` → `laser_link`, `camera_link`, `imu_link`. `robot_state_publisher` publica TF.

4. SLAM (mapeo simultáneo)

  • `ros2 launch slam_toolbox online_async_launch.py params_file:=slam.yaml`
  • Teleop: `ros2 run teleop_twist_keyboard teleop_twist_keyboard` → mueve robot por toda la zona.
  • Guarda mapa: `ros2 run nav2_map_server map_saver_cli -f my_map`.

5. Navegación autónoma (Nav2)

  • Configura `nav2_params.yaml`: controller (DWB), planner (NavFn/Smac), behavior tree, costmap (global/local), footprint robot.
  • `ros2 launch nav2_bringup navigation_launch.py map:=my_map.yaml params_file:=nav2_params.yaml`.
  • Envía goal: RViz2 → «2D Goal Pose» → robot planifica y ejecuta evitando obstáculos (LiDAR + costmap).

6. Percepción y IA (opcional)

  • Detección objetos: YOLOv8 / YOLO-NAS → `ultralytics_ros` publica `/detections` (vision_msgs).
  • Segmentación: SAM, FastSAM.
  • Reconocimiento voz: `whisper_ros` (local) o `vosk_ros`.
  • Síntesis voz: `piper_ros` (local, rápido).
  • Comportamiento complejo: Behavior Trees (BehaviorTree.CPP / Groot2) o SMACH / FlexBE.

7. Simulación (Gazebo / Isaac Sim) — desarrolla sin romper hardware

  • URDF/SDF del robot → spawn en Gazebo Harmonic / Fortress.
  • Plugins: `gazebo_ros2_control`, `libgazebo_ros_lidar.so`, `libgazebo_ros_camera.so`.
  • Mismo stack Nav2/SLAM funciona en sim → transferencia a real (sim2real).

Programación en Arduino / ESP32 (nivel maker)

// Ejemplo: control motor DC + encoder + PID velocidad + ROS 2 micro-ROS
#include 
#include 
#include 
#include 
#include 
#include 

// ... setup micro-ROS transport (Serial/USB/WiFi), nodos, publicadores/suscriptores
// Loop: read encoder → PID → PWM motor → publish odom (x, y, theta)
// Recibe cmd_vel → target velocity → PID setpoint

micro-ROS permite nodos ROS 2 en microcontroladores (ESP32, STM32, Teensy, Raspberry Pi Pico). Ideal para drivers de bajo nivel.

Buenas prácticas de software robótico

  • Git + CI/CD: versiona todo (URDF, params, launch, código). GitHub Actions: build, test, lint (clang-format, black, flake8, cpplint).
  • Testing: unit tests (gtest, pytest), integration tests (launch_testing), simulación CI.
  • Parámetros YAML + override: nada hardcodeado. `ros2 param set /node param value`.
  • Logging estructurado: `RCLCPP_INFO/DEBUG/WARN/ERROR` + `ros2 bag record` para depuración.
  • Seguridad: watchdog hardware, E-stop físico, limitadores de corriente/velocidad, zonas de seguridad (ISO 13849).
  • Documentación: README, diagramas (ROS 2: `rqt_graph`, `rqt_tf_tree`), decision log (ADR).

Recursos de aprendizaje

  • ROS 2: docs.ros.org (Tutorials), «ROS 2 Documentation» (The Construct), «Programming Robots with ROS 2» (Morgan Quigley), ROS 2 para todos (YouTube, español).
  • Nav2: navigation.ros.org (configuración, tuning).
  • SLAM Toolbox: github.com/SteveMacenski/slam_toolbox.
  • micro-ROS: micro.ros.org, tutorials.
  • Robótica móvil: «Probabilistic Robotics» (Thrun, Burgard, Fox), «Robotics, Vision and Control» (Corke).