Sensor Data in Rosbot 2.0 Pro with ROS

Hello

I have a Rosbot 2.0 Pro and I want to connect a sensor with four analogic pins. I’m trying to connect in hSens ports and supply the sensor with power supply output of Rosbot 2.0 Pro.

My problem is that I want to create a node in C++ with ROS and I don´t know how getting the sensor data.

Regards.

Hi Jaime,

hSens is directly connected to port on CORE2 (board with STM32). If you want to connect new sensor to this port, you have to modified ROSbot firmware. In readme file you will find information how to set up environment. After programming needed publishers/subscribers/services, you can go to programming actual nodes for this sensor in ROS.

Other method would be directly connecting this sensor to SBC if it is possible.

Best regards,
Hubert

Hello Hubert,

thank you for your answer.

I have tried to modify the firmware of rosbot. I have followed the step of GitHub - husarion/rosbot-stm32-firmware: Embedded, low-level firmware for STM32 microcontroller inside ROSbot. and I’m trying to modify the code of main.cpp but it’s difficult to me understand how I can add the pins to connect the sensor because it’s not explained on the website.

Do you know how I can do it?

Thanks you and best regards,
Jaime.

Hi Jaime,

What kind of sensor are you planning to use? You mentioned using analog pins and that you will power your sensor with voltage source supplied by rosbot. You probably meant 5V exposed on the back panel of rosbot (hExt/hSesn). Some of the exposed microcontroller gpio pins have analog in functionality, but you have to remember that in that mode they only support 3.3V logic. Have that in mind, otherwise you can accidently damage your robot if your sensor outputs 5V signal.

If it comes to customizing the firmware code for the ROSbot internal mcu, the best start would be to visit mbed-os documentation. The mbed-os project is a library/framework that also includes RTOS. We use it for the rosbot firmware. Developing new functionality for the firmware should be like writing any other mbed application. The microcontroller used in rosbot is ST STM32F407ZG (TARGET_CORE2 in mbed). All pins and their aliases (e.g. SENS4_PIN1 = PC_5) are defined in the file PinNames.h. You can inspect pin functionalities in the file PeripherialPins.c or in the reference manual of the mcu.
To communicate with the ros system the microcontrolller uses rosserial library. This examples should help you to add ros interface for your sensor (pulisher/subscriber etc.).

We will (probably soon) rewrite the firmware for mbed6, but it will still use the same rosserial library (at least for ros1) and much of the codebase will stay the same so moving your newly developed functionalities to a new version should be a matter of copy & paste.

Let me know if you need more specific assistance with your case.

Best Regards,
Szymon

1 Like

Hello,

thank you for your answer. I have tried to do the examples (rosserial_mbed/Tutorials - ROS Wiki) and when I execute the command ‘make deploy’ in the example of Blink or HelloWorld I receive this message (make: Nothing to be done for ‘deploy’.). But if only I execute ‘make’ this generate the compiled binary file correctly. But I don’t know where I have to copy it into the mbed device for testing.

I have changed the makefile of helloworld or Blink and I have written ‘device: TARGET_CORE2’ and I execute ‘make deploy’ again but I receive this message (make: *** No rule to make target ‘LPC1768-deploy’, needed by ‘deploy’. Stop.
)

Furthermore, I have changed the firmware in Visual Studio because mbed studio don’t find the TARGET_CORE2 when I select the device. But when I have used ‘GitHub - husarion/rosbot-stm32-firmware: Embedded, low-level firmware for STM32 microcontroller inside ROSbot.’ to upload new firmware, when I execute rosserial I receive this message:

process[rosout-1]: started with pid [7732]
started core service [/rosout]
process[serial_node-2]: started with pid [7735]
[INFO] [1628606478.453289]: ROS Serial Python Node
[INFO] [1628606478.486565]: Connecting to /dev/ttyS4 at 525000 baud
[INFO] [1628606480.607429]: Requesting topics…
[ERROR] [1628606495.619982]: Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino
[INFO] [1628606495.628955]: Requesting topics…

Do you know can I can connect the firmware new with Rosbot?

Thanks you and best regards,
Jaime.

Hi Jamie,

Sorry for the late reply. First of all, make sure you’re able to build GitHub - husarion/rosbot-stm32-firmware: Embedded, low-level firmware for STM32 microcontroller inside ROSbot. (check the repository README file for details).

The ros examples I’ve recommended to you seem to use some very old build system, so you should only focus on their source code. In the rosbot firmware repository we use PlatformIO extension to manage the build system. If the extension and all dependencies are installed you just need to run the PlatformIO: Build task to compile your project. For more info about PlatformIO check the documentation: Mbed — PlatformIO latest documentation

I prepared for you a ros example that simulates a sensor that should help you start. Here are required modification to your project:

  1. In src directory inside the project create a new subdirectory and name it ros_tests.
  2. Inside ros_tests create a new file RosMockSensorTest.h and copy the content of this gist to it. Your src dir shuld now look like this:
src
├── main.cpp
├── rosbot_kinematics.cpp
├── rosbot_kinematics.h
├── rosbot_sensors.cpp
├── rosbot_sensors.h
├── ros_tests
│   └── RosMockSensorTest.h
└── TARGET_CORE2
    ├── PeripheralNames.h
    ├── PeripheralPins.c
    ├── PinNames.h
    └── system_clock.c
  1. Add line -I$PROJECTSRC_DIR/ros_tests to build_flags in platformio.ini file.
  2. Replace content of main.cpp file with:
#include "RosMockSensorTest.h"

int main()
{
    RosMockSensorTest test_node;
    test_node.init();
    test_node.spin();
}

You can rename old main.cpp as main.cpp.old to preserve the original source code. Unfortunately, the build system used by PlatformIO doesn’t support .mbedignore files, so you can’t easily exclude .cpp files from compilation process.

You can use this example as a “boilerplate code” for testing out other ros features from “ros tutorials”. This way you will have them neatly as separate “test cases” that you can run with minimal changes to main.cpp.

Best Regards,
Szymon

1 Like

Hi Szymon,

finally I got to create a publisher with pin of core2. Thank so much for your answer.

Now I have other problem. I want to create a subscriber in my ros_workspace where I want to receive the message of publisher /adc that I have created:
Published topics:

  • /rosout_agg [rosgraph_msgs/Log] 1 publisher
  • /rosout [rosgraph_msgs/Log] 2 publishers
  • /diagnostics [diagnostic_msgs/DiagnosticArray] 1 publisher
  • /battery [sensor_msgs/BatteryState] 1 publisher
  • /pose [geometry_msgs/PoseStamped] 1 publisher
  • /velocity [geometry_msgs/Twist] 1 publisher
  • /range/fr [sensor_msgs/Range] 1 publisher
  • /range/fl [sensor_msgs/Range] 1 publisher
  • /range/rr [sensor_msgs/Range] 1 publisher
  • /range/rl [sensor_msgs/Range] 1 publisher
  • /joint_states [sensor_msgs/JointState] 1 publisher
  • /imu [sensor_msgs/Imu] 1 publisher
  • /buttons [std_msgs/UInt8] 1 publisher
  • /chatter [std_msgs/String] 1 publisher
  • /adc [rosserial_mbed/Adc] 1 publisher

Subscribed topics:

  • /rosout [rosgraph_msgs/Log] 1 subscriber
  • /cmd_vel [geometry_msgs/Twist] 1 subscriber
  • /cmd_ser [std_msgs/UInt32] 1 subscriber
  • /valores_sensor [rosserial_mbed/Adc] 1 subscriber

with rostopic echo /adc I have received the message correctly:

husarion@husarion:~/ros_workspace$ rostopic echo /adc
adc0: 22333
adc1: 22765
adc2: 23129
adc3: 19764
adc4: 0
adc5: 0

adc0: 22417
adc1: 22709
adc2: 22945
adc3: 19868
adc4: 0
adc5: 0

I have created this subscriber to receive the information:

#include <rosserial_mbed/Adc.h>
#include <ros/ros.h>
#include

void sensorCallback(const rosserial_mbed::Adc &msg)
{
ROS_INFO(“Recibido el mensaje del sensor: %d”, msg.adc0);
std::cout << “HOLALALALALAA” << std::endl;
}

int main(int argc, char *argv)
{
ros::init(argc, argv, “sensor_subscriber”);
ros::NodeHandle nh;
std::cout << “INICIANDO SUBSCRIPTOR” << std::endl;
ros::Subscriber sub = nh.subscribe(“valores_sensor”, 1, sensorCallback);
std::cout << “INICIANDO SUBSCRIPTOR” << std::endl;
ROS_INFO(“move_base_ws2812b_example: subscription was made”);
ros::spin();
/
while (ros::ok())
{
ros::spinOnce();
loop_rate.sleep();
}
*/
return 0;
}

But I only receive message of int main() not the call back:

husarion@husarion:~/ros_workspace$ rosrun solar_sensor solar_sensor_node
INICIANDO SUBSCRIPTOR
INICIANDO SUBSCRIPTOR
[ INFO] [1630930405.515032775]: move_base_ws2812b_example: subscription was made

I haven’t compilation errors. Do you know what’s happening?

Best Regards,
Jaime

Hi,
I really recommend to go through ros tutorials. In your case, you made a simple mistake. Your firmware publishes to topic /adc, but in your ros node you try to read topic /valores_sensor. See the list of subscribed topics. You can think of topics as pipes. If you put something in on one end you can expect to receive it on the other, but it have to be the same pipe :slight_smile:

Regards,
Szymon