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

rosserial problems with digitalWrite(2,HIGH)

asked 2012-07-28 16:03:21 -0500

ThomasK gravatar image

updated 2012-07-29 14:54:57 -0500

Hey all,

I'm trying to use rosserial_arduino on top of the arduimu code base (running on the ArduIMU+ v2). My problem is that part of the IMU's initialization is a call to

digitalWrite(2,HIGH);

but this somehow causes rosserial to lose sync with the IMU. When I run the code with that line commented out it successfully advertises the topic, but otherwise I only get "Lost sync with device, restarting..." messages.

Here the setup() function:

void setup()
{ 
   //IMU setup
   Serial.begin(38400);
   pinMode(2,OUTPUT); //Serial Mux
   //digitalWrite(2,HIGH); //Serial Mux
   pinMode(5,OUTPUT); //Red LED
   pinMode(6,OUTPUT); // Blue LED
   pinMode(7,OUTPUT); // Yellow LED
   pinMode(GROUNDSTART_PIN,INPUT);  // Remove Before Fly flag (pin 6 on ArduPilot)
   digitalWrite(GROUNDSTART_PIN,HIGH);

   //ROS setup
   nh.initNode();
   nh.advertise(pub_imu);
   imu_msg.header.frame_id = "/imu_link";

   // ... some other imu initialization calls ... 
};

Thanks,
Thomas

edit retag flag offensive close merge delete

Comments

Hi Thomas, I don't have an ArduIMU, but the fact that line says "//Serial Mux" behind it leads me to believe the unit is sending "non-ROS" serial messages over the port, which might be confusing the ROS msg system. Try looking at what is coming over the port from the unit without ROS.

dougbot01 gravatar image dougbot01  ( 2012-07-28 17:05:12 -0500 )edit

You might want to look at the serial stream with this program https://help.ubuntu.com/community/Cutecom

dougbot01 gravatar image dougbot01  ( 2012-07-28 17:06:47 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-07-31 10:58:16 -0500

Dariush gravatar image

From my experience most crashes on the atmega are memory related. Most often you simply run out of stack and start corrupting your heap (i.e. globally defined variables). This can be pretty devious and hard to debug, as the program running might not behave weird until some time later.

A simple and very effective debugging help is measuring the stack size. You should always keep a healthy amount of stack free for use (at least 1 byte ;). There is code on the Internets that can help you measure the stack size at runtime. In my last project I used this piece of code: (caveat: the site in German, however the code has English comments): http://www.rn-wissen.de/index.php/Speicherverbrauch_bestimmen_mit_avr-gcc

cheers Dariush

edit flag offensive delete link more

Comments

Thanks, I'll take a look at it! :) (I'm Austrian, so German is not an issue ;) )

ThomasK gravatar image ThomasK  ( 2012-08-01 20:46:16 -0500 )edit
0

answered 2012-07-29 16:53:26 -0500

ThomasK gravatar image

Thanks for the tip. I've encountered a different problem now though which I hadn't realized yesterday when I had all the other code in loop() commented out. The library runs fine without rosserial but once I start including basic rosserial functionality (nodehandle and publisher) some code seems to suddenly starts crashing (or at least that's my conclusion after using cutecom in combination with print-debugging). For example basic code like

for(int c=0; c<3; c++)
  Omega_P[c] = errorRollPitch[c] + Kp_ROLLPITCH*Accel_weight;

inside the loop() function suddenly crashes (all variables are defined globally).
Earlier today I also had the problem that a simple access to a globally defined array from within a function defined in another pde file caused a crash but accessing it inside the loop() function worked fine (passing the array to the function resulted in the same), but somehow this crash magically disappeared ...

Any idea what could be going on here? :/ It's getting kinda tedious to get this working.

edit flag offensive delete link more

Comments

I had some similar experience while trying to get rosserial running on a Atmega168 based Motorcontroller. There, the problem was the low amount of memory available. You can read about it here: http://answers.ros.org/question/28890/using-rosserial-for-a-atmega168arduino-based/

Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-07-29 20:07:54 -0500 )edit

Thanks ... I realized how easy it is to read serial connections with python so i just went over to using the unmodified arduimu software with a serial client in python parsing the output and publishing Imu msgs.

ThomasK gravatar image ThomasK  ( 2012-07-30 15:51:53 -0500 )edit

That's actually the solution I also ended up using on my motorcontroller ;)

Stefan Kohlbrecher gravatar image Stefan Kohlbrecher  ( 2012-07-30 22:19:01 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2012-07-28 16:03:21 -0500

Seen: 1,070 times

Last updated: Jul 31 '12