Follow MaxBotix:
Ask A Question

Robot Operating System (ROS) used with a MaxBotix Ultrasonic Sensor


Robot Operating System (ROS)A MaxBotix ultrasonic sensor installed in a robot using the Robot Operating System (ROS) provides the valuable data needed to solve the complex obstacle avoidance and navigation problems on your autonomous robots. The Robot Operating System is a powerful resource that enables collaborative development of truly complex robot software. ROS is designed to be run on any Ubuntu device from a Raspberry Pi to a dedicated PC, learn more about how to connect a Raspberry Pi with a USB ultrasonic sensor.

For a great crash course, ROS Tutorial part 1 provides a refresher on ROS and the second video shows robots using Maxbotix ultrasonic sensors, Gentle Intro to ROS - Part 2. It also has excellent presentation slides to provide a strong intellectual foundation. Many of your more advanced questions can be answered within the ROS wiki.

Shop Easy-to-Use Ultrasonic Sensors for the Robot Operating System

Check out our exclusive selection of low-cost ROS compatible ultrasonic sensors for a wide variety of applications. Click here to see the full list.

Increase Productivity with the Robot Operating System

ROS integrates the numerous tasks and components operating on a robot and allows you to break down complex problems into more manageable pieces. ROS connects all messages being sent only with the programs interested in those messages. This means you can write a program without worrying about coding all the inputs and other subroutines.

The collaborative nature of the Robot Operating Systems allows you to capitalize on the shared work of the community. This lets you focus on creating only the pieces of software you need without having to reinvent the wheel.

Robot Operating System 8 Year Montage

For users looking to quickly connect an ultrasonic sensor and go, our USB sensors are a real standout. You can attach a USB sensor to your robot with a standard micro USB cable like a standard phone charging cable. At this point, it doesn’t take much more. All that is left is to write a few simple lines of code and you can fully integrate your MaxBotix sensor into your robot with ROS. Feel free to review and use the following example from the presentation slides to the linked ROS videos.

MaxBotix Ultrasonic Sensor int main( int argc, char **argv)

ros::init( argc, argv, "publish_sonar");
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise("sonar0", 1);
sensor_msgs::Range rangeMsg;
char rxBuf[80];
float range;
int fd;
fd = open("/dev/ttyUSB0", O_EXCL);
if (fd < 0)

std::cerr << "Error opening sonar tty\n";


// Maxbotix output is R1234, range in mm
int i = 0;
while(read(fd, &rxBuf[i], 1)) {
if (rxBuf[i] == '\r') {

rxBuf[i] = '\0';

range = strtof(&rxBuf[1], NULL) / 1000; // output in meters
rangeMsg.range = range;
rangeMsg.header.stamp = ros::Time::now();
ROS_INFO_STREAM("Sonar msg: " << std::string(rxBuf) << " range: " << range);



With the flexibility of ROS and the number of packages that are already available, creating software ROS can greatly simplify the task of creating robust robot software. While creating robot software with the robot operating system lets you leverage the collective expertise of the community and produce more robust and flexible robots, being able to install an easy to use MaxBotix range finder will help you produce your robot even faster.

Signup for notification of our exciting new products and periodic new letters. We are excited to provide the latest information from MaxBotix Inc.