{"slug": "android-ros-2-building-a-robot-control-app-with-kotlin", "title": "Android + ROS 2: Building a Robot Control App with Kotlin", "summary": "A developer demonstrates how to build an Android robot control app in Kotlin that communicates with a ROS 2 robot, using a bridge or gateway to expose only necessary topics. The app uses Jetpack Compose for the UI, Kotlin coroutines and StateFlow for telemetry, and includes a command watchdog for safety. The tutorial emphasizes testing against a simulator before deploying to physical hardware.", "body_md": "Physical AI is bringing together robotics, edge computing, computer vision, and intelligent mobile interfaces. Android is a useful companion platform because modern phones and tablets provide touch interfaces, cameras, sensors, networking, and strong edge-computing capabilities.\n\nIn this tutorial, we will design an Android application in Kotlin that communicates with a ROS 2 robot. The app will provide a simple control interface for sending movement commands and receiving robot telemetry.\n\nA practical architecture can look like this:\n\n```\nAndroid App\n   |\n   | ROS 2 bridge / WebSocket / MQTT\n   v\nROS 2 Middleware\n   |\n   +---- /cmd_vel ----> Robot Base\n   |\n   +---- /odom -------> Telemetry\n   |\n   +---- /battery ----> Battery Status\n```\n\nThe Android application should not directly control motors. Instead, it communicates with a ROS 2 node or bridge responsible for validating commands and interfacing with the robot.\n\nCreate a Kotlin Android project using Android Studio.\n\nA clean package structure is:\n\n```\ncom.example.robotcontroller\n├── ui\n├── ros\n├── model\n├── network\n└── MainActivity.kt\n```\n\nKeep the ROS communication layer separate from the Compose UI so that the application can later switch between a simulator, development robot, or production robot.\n\nCreate a simple command model:\n\n```\ndata class VelocityCommand(\n    val linearX: Double,\n    val angularZ: Double\n)\n```\n\nThe UI can map buttons or a virtual joystick to these values.\n\nFor example:\n\n```\nfun moveForward() = VelocityCommand(\n    linearX = 0.5,\n    angularZ = 0.0\n)\n\nfun stop() = VelocityCommand(\n    linearX = 0.0,\n    angularZ = 0.0\n)\n```\n\nThe communication layer then converts the command into the message format expected by your ROS 2 bridge.\n\nA simple control panel can be created with Jetpack Compose:\n\n``` php\n@Composable\nfun RobotControls(\n    onForward: () -> Unit,\n    onBackward: () -> Unit,\n    onLeft: () -> Unit,\n    onRight: () -> Unit,\n    onStop: () -> Unit\n) {\n    Column {\n        Button(onClick = onForward) {\n            Text(\"Forward\")\n        }\n\n        Row {\n            Button(onClick = onLeft) {\n                Text(\"Left\")\n            }\n\n            Button(onClick = onStop) {\n                Text(\"Stop\")\n            }\n\n            Button(onClick = onRight) {\n                Text(\"Right\")\n            }\n        }\n\n        Button(onClick = onBackward) {\n            Text(\"Backward\")\n        }\n    }\n}\n```\n\nFor a real robot, replace these buttons with a joystick or gesture-based controller.\n\nThe Android app needs a communication mechanism between the mobile device and ROS 2. A common architecture is to expose selected ROS 2 topics through a bridge or gateway.\n\nThe Android client can then publish commands such as:\n\n```\n/cmd_vel\n```\n\nand subscribe to telemetry topics such as:\n\n```\n/odom\n/battery_state\n/robot_status\n```\n\nAvoid exposing the entire ROS graph directly to an untrusted mobile client. Expose only the topics and services required by the application.\n\nRepresent telemetry in Kotlin:\n\n```\ndata class RobotTelemetry(\n    val battery: Float,\n    val x: Double,\n    val y: Double,\n    val connected: Boolean\n)\n```\n\nUse Kotlin coroutines and `StateFlow`\n\nto expose updates to Compose:\n\n```\nprivate val _telemetry = MutableStateFlow(\n    RobotTelemetry(0f, 0.0, 0.0, false)\n)\n\nval telemetry: StateFlow<RobotTelemetry> = _telemetry\n```\n\nCompose can collect this state and update the dashboard automatically.\n\nA robot-control application should include a reliable stop mechanism.\n\nImplement:\n\nA particularly useful technique is a command watchdog: if the robot does not receive a valid command within a defined interval, the control node should command zero velocity.\n\nBefore connecting physical hardware, test the Android application against a simulated ROS 2 robot.\n\nA simulator lets you verify:\n\nThis dramatically reduces the risk of testing incorrect commands on physical hardware.\n\nFor a production system, consider:\n\n```\nAndroid / Kotlin\n       |\n   Secure Gateway\n       |\n      ROS 2\n       |\n Navigation / Perception\n       |\n Robot Hardware\n```\n\nThis separation allows the Android application to remain a user interface while ROS 2 handles robotics workloads.\n\nAndroid and Kotlin can provide a powerful human interface for Physical AI systems. By combining Jetpack Compose, Kotlin coroutines, secure networking, and ROS 2, you can build mobile applications that monitor and control robots without coupling the Android UI directly to robot hardware.\n\nThe same architecture can later be extended with camera streaming, AI perception, voice commands, autonomous navigation, and LLM-based robot control.\n\nSDK Flutter: [https://github.com/v-modal/vmodal_sdk_flutter](https://github.com/v-modal/vmodal_sdk_flutter)\n\nSDK Android: [https://github.com/v-modal/vmodal_sdk_android](https://github.com/v-modal/vmodal_sdk_android)\n\nDiscord: [https://discord.gg/K72z28KUx](https://discord.gg/K72z28KUx)", "url": "https://wpnews.pro/news/android-ros-2-building-a-robot-control-app-with-kotlin", "canonical_source": "https://dev.to/vmodal_ai/android-ros-2-building-a-robot-control-app-with-kotlin-59m1", "published_at": "2026-08-17 20:24:21+00:00", "updated_at": "2026-08-17 20:44:08.175567+00:00", "lang": "en", "topics": ["robotics", "developer-tools"], "entities": ["Android", "Kotlin", "ROS 2", "Jetpack Compose"], "alternates": {"html": "https://wpnews.pro/news/android-ros-2-building-a-robot-control-app-with-kotlin", "markdown": "https://wpnews.pro/news/android-ros-2-building-a-robot-control-app-with-kotlin.md", "text": "https://wpnews.pro/news/android-ros-2-building-a-robot-control-app-with-kotlin.txt", "jsonld": "https://wpnews.pro/news/android-ros-2-building-a-robot-control-app-with-kotlin.jsonld"}}