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

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

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

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

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

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

kmhallen gravatar image

From message definition

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


Thank you for both the answer and the link.

Nap gravatar image Nap  ( 2014-11-08 18:38:35 -0500 )edit

Question Tools

1 follower


Asked: 2014-11-08 10:17:09 -0500

Seen: 269 times

Last updated: Nov 08 '14