Ask Your Question
0

Code Arduino to ROS

asked 2016-03-28 09:10:57 -0500

Emilien gravatar image

updated 2016-03-28 11:22:18 -0500

ahendrix gravatar image

Hi, I have my robot Arduino and i want to command it with ROS. I install ROS and Rosserial_arduino in my raspberry and i want to command my Robot. can you help me please to add the instructions of ROS in my code arduino? my code is in this page: https://electronics4all.wordpress.com... Thanks

edit retag flag offensive close merge delete

Comments

Please post the code here. Otherwise the answer will become useless for others if the link to the blog does not work anymore.

NEngelhard gravatar image NEngelhard  ( 2016-03-28 09:59:52 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-03-28 10:17:52 -0500

Emilien gravatar image

#include <afmotor.h> #include <servo.h> #include <newping.h>

#define TRIG_PIN A4 // Pin A4 on the Motor Drive Shield soldered to the ultrasonic sensor #define ECHO_PIN A5 // Pin A5 on the Motor Drive Shield soldered to the ultrasonic sensor #define MAX_DISTANCE 200 // sets maximum useable sensor measuring distance to 200cm #define MAX_SPEED 180 // sets speed of DC traction motors to 180/256 or about 70% of full speed - to get power drain down. #define MAX_SPEED_OFFSET 10 // this sets offset to allow for differences between the two DC traction motors #define COLL_DIST 10 // sets distance at which robot stops and reverses to 10cm #define TURN_DIST COLL_DIST+10 // sets distance at which robot veers away from object (not reverse) to 20cm (10+10) NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE); // sets up sensor library to use the correct pins to measure distance.

AF_DCMotor motor1(1, MOTOR12_1KHZ); // create motor #1 using M1 output on Motor Drive Shield, set to 1kHz PWM frequency AF_DCMotor motor2(4, MOTOR12_1KHZ); // create motor #2, using M2 output, set to 1kHz PWM frequency Servo myservo; // create servo object to control a servo

int pos = 0; // this sets up variables for use in the sketch (code) int maxDist = 0; int maxAngle = 0; int maxRight = 0; int maxLeft = 0; int maxFront = 0; int course = 0; int curDist = 0; String motorSet = ""; int speedSet = 0;

//-------------------------------------------- SETUP LOOP ---------------------------------------------------------------------------- void setup() { myservo.attach(9); // attaches the servo on pin 9 (SERVO_2 on the Motor Drive Shield to the servo object myservo.write(90); // tells the servo to position at 90-degrees ie. facing forward. delay(2000); // delay for two seconds checkPath(); // run the CheckPath routine to find the best path to begin travel motorSet = "FORWARD"; // set the director indicator variable to FORWARD myservo.write(90); // make sure servo is still facing forward moveForward(); // run function to make robot move forward } //------------------------------------------------------------------------------------------------------------------------------------

//---------------------------------------------MAIN LOOP ------------------------------------------------------------------------------ void loop() { checkForward(); // check that if the robot is supposed to be moving forward, that the drive motors are set to move forward - this is needed to overcome some issues with only using 4 AA NiMH batteries checkPath(); // set ultrasonic sensor to scan for any possible obstacles }

edit flag offensive delete link more

Comments

and i have also all function of this code

Emilien gravatar image Emilien  ( 2016-03-28 10:18:47 -0500 )edit

Please edit your question instead of posting something as an answer. What have your tried so far? What do you want? Where is your problem?

NEngelhard gravatar image NEngelhard  ( 2016-03-28 10:53:45 -0500 )edit

i want to add instruction of ROS into my code

Emilien gravatar image Emilien  ( 2016-03-28 11:25:14 -0500 )edit

That's a bit inexact. Why? What kind of instructions? What do you want to achieve?

NEngelhard gravatar image NEngelhard  ( 2016-03-28 12:57:36 -0500 )edit

i have arduino robot with the code all is ok. i want to command it with arduino. so i installed ROS in raspberry and rosserial. now, i want to converte my code arduino to code arduino with ROS.

Emilien gravatar image Emilien  ( 2016-03-28 14:59:25 -0500 )edit
1

But where is your problem? This is a forum where you can ask for help if you are stuck and no place where others are doing the work for you.

NEngelhard gravatar image NEngelhard  ( 2016-03-29 01:46:40 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-28 09:10:57 -0500

Seen: 265 times

Last updated: Mar 28 '16