DEV Community

vmodal_ai
vmodal_ai

Posted on

Building a Flutter App for Autonomous Robot Control with ROS 2

Building a Flutter App for Autonomous Robot Control with ROS 2

Physical AI is moving robots from isolated machines to intelligent systems that can perceive, reason, and act in the physical world. Flutter can provide a modern cross-platform interface for monitoring and controlling robots.

What You Will Build

The Flutter application will:

  • Connect to a robot backend through WebSocket or MQTT
  • Display robot telemetry
  • Show navigation status
  • Send movement commands
  • Support autonomous and manual control modes

Understanding the Architecture

Flutter App
     |
     | WebSocket / MQTT
     v
Robot Gateway
     |
     | ROS 2 Topics / Services / Actions
     v
ROS 2 System
     |
     +-- Navigation Stack
     +-- Sensors
     +-- Motor Controller
     +-- SLAM
     +-- AI Models
Enter fullscreen mode Exit fullscreen mode

ROS 2 Communication

ROS 2 provides:

  • Topics for continuous data streams
  • Services for request-response operations
  • Actions for long-running tasks

Example robot topics:

/cmd_vel
/odom
/scan
/battery_state
/navigate_to_pose
Enter fullscreen mode Exit fullscreen mode

Creating the Flutter Project

flutter create robot_control_app
cd robot_control_app
Enter fullscreen mode Exit fullscreen mode

Add dependencies:

dependencies:
  flutter:
    sdk: flutter
  web_socket_channel: ^2.4.0
  flutter_bloc: ^8.1.0
Enter fullscreen mode Exit fullscreen mode

Creating a Robot State Model

class RobotState {
  final double battery;
  final double velocity;
  final String navigationStatus;

  RobotState({
    required this.battery,
    required this.velocity,
    required this.navigationStatus,
  });
}
Enter fullscreen mode Exit fullscreen mode

Connecting Through WebSocket

import 'dart:convert';
import 'package:web_socket_channel/web_socket_channel.dart';

class RobotSocketService {
  final WebSocketChannel channel;

  RobotSocketService(String url)
      : channel = WebSocketChannel.connect(Uri.parse(url));

  Stream get stream => channel.stream;

  void sendCommand(Map<String, dynamic> command) {
    channel.sink.add(jsonEncode(command));
  }

  void dispose() {
    channel.sink.close();
  }
}
Enter fullscreen mode Exit fullscreen mode

Sending Movement Commands

robotSocketService.sendCommand({
  "type": "velocity",
  "linear": 0.5,
  "angular": 0.0,
});
Enter fullscreen mode Exit fullscreen mode

The robot gateway can convert this command into a ROS 2 message and publish it to /cmd_vel.

Building the Control Interface

ElevatedButton(
  onPressed: () {
    sendForwardCommand();
  },
  child: const Text("Move Forward"),
)
Enter fullscreen mode Exit fullscreen mode

Production interfaces can use virtual joysticks, gesture controls, voice commands, and AI-assisted navigation.

Adding Autonomous Mode

{
  "type": "navigate",
  "x": 5.0,
  "y": 2.5,
  "yaw": 1.57
}
Enter fullscreen mode Exit fullscreen mode

The ROS 2 navigation stack can then calculate the route and move the robot autonomously.

Managing State with BLoC

Useful events include:

RobotConnected
RobotDisconnected
TelemetryUpdated
NavigationStarted
NavigationCompleted
BatteryUpdated
Enter fullscreen mode Exit fullscreen mode

Production Considerations

A production robot control application should include:

  • Authentication
  • Encrypted communication
  • Command validation
  • Emergency stop controls
  • Reconnection logic
  • Telemetry buffering
  • Audit logging

Critical safety checks should remain on the robot or backend rather than relying only on the mobile client.

Conclusion

Flutter and ROS 2 are a powerful combination for Physical AI applications. ROS 2 manages robotics communication and autonomy, while Flutter provides a flexible cross-platform interface for monitoring and controlling intelligent physical systems.

Useful Links

Website: www.v-modal.com

SDK Flutter: https://github.com/v-modal/vmodal_sdk_flutter

SDK Android: https://github.com/v-modal/vmodal_sdk_android

Discord: https://discord.gg/K72z28KUx

Top comments (0)