ROS message types and AVR message type problem [closed]

asked 2012-06-17 09:06:46 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hi I am making a ROS interface for a small custom robot. I am using rosserial and able to exchange string and bool standard messages between ROS and ATmega32 mcu. But while sending uint8 messages from ROS to AVR i am getting a problem described below.

I am trying to vary speed of a DC motors, for this i made a function ( void velocity (uint8_t left_motor,uint8_t right_motor);) that takes input of type uint8_t and vary the speed accordingly. ( 255 = full speed, 0 = stop).

subscriber function:

void motor_velocity( const sparkV_msg::velocity& msg){
    velocity(msg.leftV,msg.rightV);
        if(msg.start)
            {
            if(msg.left)
                if(msg.right)
                    forward();
                else
                    right();
            else
                if(msg.right)
                    left();
                else
                    back();
            } 
        else 
            stop();
}

Message file:

bool left
bool right
bool start
uint8 leftV
uint8 rightV

Velocity function:

void velocity (uint8_t left_motor, uint8_t right_motor)
{
 OCR1AH = 0x00;
 OCR1AL = left_motor; 
 OCR1BH = 0x00;
 OCR1BL = right_motor;
}

Publishing message:

rostopic pub -1 /motor sparkV_msg/velocity -- true false true 50 50

Now the motor rotates according to the bool values send, but its speed does not varies. ( in fact speed is equal to the first message published and does not changes with second, third and so on messages.)

EDIT 1

I am only publishing in terminal using the above publishing message. But with different values like

  rostopic pub -1 /motor sparkV_msg/velocity -- false true true 150 150

I also did a little experiment by passing 8 bool messages named s0L,s1L,s2L,...,s7L and then in the subscriber code for AVR mcu converting 8 bool into uint8_t

void motor_velocity( const sparkV_msg::velocity& msg){
uint8_t leftV=0;
uint8_t rightV=0;
        if(msg.start)
            {
            if(msg.left)
                if(msg.right)
                    forward();
                else
                    right();
            else
                if(msg.right)
                    left();
                else
                    back();
            } 
        else 
            stop();
leftV=((msg.s7L*128)+(msg.s6L*64)+(msg.s5L*32)+(msg.s4L*16)+(msg.s3L*8)+(msg.s2L*4)+(msg.s1L*2)+(msg.s0L)); // converting 8 bools to uint8_t
//rightV=((msg.s1R*4)+(msg.s2R*2)+(msg.s3R*1));
velocity(leftV,0);
}

The above code works perfectly by sending 8 bool no. and then converting it, but if i send only one uint8 as mentioned in the start it does not works.

The velocity functions works properly, i have verified separately without introducing ROS messages by passing uint8_t values .

Is there any problem with sending uint8 values? Tried a lot but not able to figure out. Any suggestion ? I am using the same Makefile on [ROS AVR UART TUTORIAL]. (http://www.ros.org/wiki/rosserial_client/Tutorials/Using%20rosserial%20with%20AVR%20and%20UART)

Thanks
system :ROS electric , Ubuntu 11.10 , ROS latest up to date.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2015-03-09 20:30:09.112232

Comments

Your message doesn't look bad and there shouldn't be any problems with uint8 data types. Can you please edit your question and add a line how you publish the second message. Try publishing at a rate of say 10Hz just to make sure that the problem is not due to lost packages.

Lorenz gravatar image Lorenz  ( 2012-06-17 23:16:33 -0600 )edit

Thanks Lorenz, I have edited the question and also added some more details. Still not able to solve the problem.

AbhishekMehta gravatar image AbhishekMehta  ( 2012-06-18 04:22:13 -0600 )edit