ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

turn on/off a dc motor by using an IR range sensor with arduino and ros

asked 2016-08-20 22:46:52 -0600

Abbas gravatar image

Hi, I am new for using Ros. I used an example to read the range data from IR range sensor by using Arduino kit and ROS. Now, I want to use the data from IR range sensor to turn on/off a small dc motor by using Arduino and ROS (for example if the distance from IR range sensor is more than 50 cm, we send a command to run the motor, and else turn off the motor). I appreciate for any help.

Thanks, Abbas

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-08-21 03:39:09 -0600

Mark Rose gravatar image

First, please don't ask the same question twice. It doesn't get answered faster, and might cause some people to disregard your question as being impolite. Better to edit your original question than ask a duplicate question with different wording.

There is more than one way to lay out your logic among ROS nodes. Perhaps the most ROS-like way might be this:

  • One node that reads the range sensor and publishes the range as a ROS sensor_msgs/Range message.
  • A decision node that reads the Range message and publishes another message to turn on or off the motor, perhaps as std_msgs/Bool.
  • A third node that listens for the Bool message and turns on or off the motor.

This arrangement has the advantage that input nodes, output nodes, and logic nodes are distinct and independent.

However, you might decide to collapse these into two or one node to be faster or more efficient. I don't know what software you are using on the Arduino side. I have used both rosserial_arduino and ros_arduino_bridge. rosserial makes programming on the Arduino side more ROS-like, but has fairly high RAM usage, so is more suitable for mega-class Arduinos (or Teensy, for example). ros_arduino_bridge may require you to modify the code to accept a new command to turn on or off the motor. (It has support for some motor shields.) If you give some more details, I may be able to point you to forks off of ros_arduino_bridge that do something like you want.

edit flag offensive delete link more

Comments

Just a comment on:

First, please don't ask the same question twice

it could well be that due to the moderation system @Abbas thought his post got lost and decided to post it again. Then when a moderator lets his initial post through, his second also gets posted. Result: double-post.

gvdhoorn gravatar image gvdhoorn  ( 2016-08-21 05:19:25 -0600 )edit

Dear sir, Sorry for duplication the question, I did not know that I posted my question twice. Thank you so much for your help. I think it will be useful for me. I use rosserial_arduino software and I also use Arduino Uno kit for this project . Thanks, Abbas

Abbas gravatar image Abbas  ( 2016-08-21 10:15:39 -0600 )edit

No problem, and sorry if the double-post was due to the moderation system. I have not had stable results with rosserial on an Uno. It uses a lot of RAM, due to design choices. I've given up on it and use ros_arduino_bridge instead.

Mark Rose gravatar image Mark Rose  ( 2016-08-22 10:51:22 -0600 )edit

Hi Mark, Thank you for your answer. I am new to use ROS (I know basic knowledge about ROS), can I ask you to explain me how can I do the project in more details? Thanks, Abbas

Abbas gravatar image Abbas  ( 2016-08-22 17:32:25 -0600 )edit

Sure. My robot uses a Pololu A-Star board for robot control, and a Raspberry Pi for the ROS side. I've written a page for my study group.

Mark Rose gravatar image Mark Rose  ( 2016-08-22 19:35:13 -0600 )edit

That page is a little specific to the robot design our study group is using, because of the A-Star board, but has information about ros_arduino_bridge that is applicable to any Arduino. We use I2C to link the RPi and Arduino, but that requires a level shifter, so you may want to use a USB cable.

Mark Rose gravatar image Mark Rose  ( 2016-08-22 19:36:31 -0600 )edit

You don't have to use a Raspberry Pi, of course, though I presume you will have some Linux microcontroller on the robot. You'll have to modify ros_arduino_bridge to support your motor driver shield or wiring. I'm assuming you will have encoders. If not, navigation will be difficult.

Mark Rose gravatar image Mark Rose  ( 2016-08-22 19:39:17 -0600 )edit

Maybe let me know a bit more about you robot so I can give you more relevant information.

Mark Rose gravatar image Mark Rose  ( 2016-08-22 19:39:46 -0600 )edit

Question Tools

Stats

Asked: 2016-08-20 22:46:52 -0600

Seen: 629 times

Last updated: Aug 21 '16