Ask Your Question
0

can't convert uint8 to uint8 to republish a field from a message.

asked 2014-11-08 10:17:09 -0600

Nap gravatar image

This might sound like a really silly question but I've been trying to figure out the answer for the last two hours. :(
I have a Message that includes a uint8 field. In the callback that receives that message, I need to republish it after performing a calculation. I'm using a temporary variable, that is of the same class as the callback message type, and the republished message is a simple std_msgs::UInt8.

nxt::LegoNXTROS_Status currStatus;

void statusCallBack(const nxt::LegoNXTROS_Status::ConstPtr& msg) {
    currStatus.leftMotorEncoder = msg->leftMotorEncoder;
    currStatus.rightMotorEncoder = msg->rightMotorEncoder;
    currStatus.sonarSensor = msg->sonarSensor;
    currStatus.leftTouchSensor = msg->leftTouchSensor;
    currStatus.rightTouchSensor = msg->rightTouchSensor;
    std_msgs::UInt8 perturbedmsg = currStatus.sonarSensor; <<ERROR HERE
    pWhiteNoiseAdder.publish(perturbedmsg);
}

sWhiteNoiseAdder = nWhiteNoiseAdder.subscribe("LegoNXTROS_Status", 1000, statusCallBack);
pWhiteNoiseAdder = nWhiteNoiseAdder.advertise<std_msgs::UInt8>("PerturbedSonar",10);

Message Definition below:

# LegoNXTROS_Status message
# Defines the protocol for publishing the NXT robot's status.
#
uint16 leftMotorEncoder
uint16 rightMotorEncoder
uint8 sonarSensor
bool leftTouchSensor
bool rightTouchSensor

Could someone please help me through this?
Cheers,
Nap

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-11-08 17:09:35 -0600

kmhallen gravatar image

From message definition http://docs.ros.org/hydro/api/std_msg...

std_msgs::UInt8 perturbedmsg;
perturbedmsg.data = currStatus.sonarSensor;
edit flag offensive delete link more

Comments

Thank you for both the answer and the link.

Nap gravatar imageNap ( 2014-11-08 18:38:35 -0600 )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: 2014-11-08 10:17:09 -0600

Seen: 107 times

Last updated: Nov 08 '14