ROS serial preventing other serial ports being used on mbed device (Nucleo F303K8)

asked 2018-02-02 08:06:41 -0500

eoj gravatar image

updated 2018-02-02 10:23:10 -0500

Hi,

Note to moderator I cannot find a duplicate of this question

I’m using ROS serial on a Nucleo F303K8 and want to use the extra serial port on the device for SBUS comms. But whenever I try to initialize it ROS serial stops working, I have checked the pins I have requested don’t conflict with the ones ROS serial uses, but have had no luck.

If you comment out the line "BufferedSerial sBusSerial(PA_2,PA_3);" ROS serial starts working again, but with the line in there the ROS serial python node does doesn't pick up the ROS topics.

I’m using the mbed online development environment to do the coding, please find my code below, does anyone know what I'm doing wrong? Please note the code to send the SBUS commands is not included for simplicity.

Thanks In advance Joe

#include "mbed.h"
#include <ros.h>
#include <std_msgs/Int16.h>
#include "BufferedSerial.h"

BufferedSerial sBusSerial(PA_2,PA_3);
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);

ros::NodeHandle nh;

void SetPitch (const std_msgs::Int16& PitchState)
{
    if(PitchState.data>0)
    {
        //SBUS_Build_Packet();
        myled1 = 1;
        //sBusSerial.write(SBUS_Packet_Data, 25);
    }
    else
    {
        myled1 = 0;
    }
}

void SetYaw (const std_msgs::Int16& YawState)
{
    if(YawState.data>0)
    {
        //SBUS_Build_Packet();
        //sBusSerial.write(SBUS_Packet_Data, 25);
    }
}

ros::Subscriber<std_msgs::Int16> SubSetPitch("Gimble_Pitch", SetPitch );
ros::Subscriber<std_msgs::Int16> SubSetYaw("Gimble_Yaw", SetYaw );

int main() {

    nh.initNode();
    nh.subscribe(SubSetPitch);
    nh.subscribe(SubSetYaw);

    while(1) {
        //myled1 = 1; // LED is ON
        //wait(0.05); // 200 ms
        //myled1 = 0; // LED is OFF
        //wait(0.05); // 1 sec
        nh.spinOnce();

    }
}
edit retag flag offensive close merge delete