ROS teleop core2+rp3

Hey I’m trying to control the Core2 board with a joystisck connected to ros and sending a twist message.
However when I try to build my code I get the following errors:
Linking CXX executable main.elf
CMakeFiles/main.elf.dir/main.cpp.o:(.bss.nh+0x0): multiple definition of nh' CMakeFiles/main.elf.dir/ros.cpp.o:(.bss.nh+0x0): first defined here CMakeFiles/main.elf.dir/main.cpp.o: In function hMain()’:
main.cpp:(.text._Z5hMainv+0x0): multiple definition of `hMain()’
CMakeFiles/main.elf.dir/ros.cpp.o:ros.cpp:(.text._Z5hMainv+0x0): first defined here
collect2: error: ld returned 1 exit status
CMakeFiles/main.elf.dir/build.make:110: recipe for target ‘main.elf’ failed
make[3]: *** [main.elf] Error 1
CMakeFiles/Makefile2:157: recipe for target ‘CMakeFiles/main.elf.dir/all’ failed
make[2]: *** [CMakeFiles/main.elf.dir/all] Error 2
CMakeFiles/Makefile2:204: recipe for target ‘CMakeFiles/main.hex.dir/rule’ failed
make[1]: *** [CMakeFiles/main.hex.dir/rule] Error 2
Makefile:162: recipe for target ‘main.hex’ failed
make: *** [main.hex] Error 2

MY CODE:
#include
#include
#include “hFramework.h”
#include “hCloudClient.h”
#include <ros.h>
#include “std_msgs/String.h”
#include “geometry_msgs/Twist.h”

using namespace hFramework;
ros::NodeHandle nh;

void twistCallback(const geometry_msgs::Twist &twist)
{
float gas = twist.linear.x;
float nozzle = twist.linear.y;
}

void printfOnConsoleInWebIDE()
{
for (;:wink: {
platform.printf(“asd %d\r\n”, sys.getRefTime());
sys.delay(1000);
}
}

void cfgHandler()
{
//uncomment if you want to stream video from your project using smartphone
platform.ui.video.enableTransmission();
platform.ui.loadHtml({Resource::WEBIDE, “/ui.html”});
}

void onKeyEvent(KeyEventType type, KeyCode code)
{
//press “up key” on your keyboard in your device UI
if (code == KeyCode::Up) {
if (type == KeyEventType::Pressed) {
LED3.on();
} else {
LED3.off();
}
}
}

void onButtonEvent(hId id, ButtonEventType type)
{
static int cnt = 0;
if (id == “btn1”) {
UiButton b = platform.ui.button(“btn1”);
if (type == ButtonEventType::Pressed) {
b.setText(“pressed %u”, cnt++);
} else {
b.setText(“released %u”, cnt++);
}
LED1.toggle();
}
}

void checkADC()
{
hSens4.pin1.enableADC(); // enable ADC on pin1 on hSens4 port
hExt.pin1.enableADC(); // enable ADC on pin1 on hExt port
float val1 = hExt.pin3.analogReadVoltage(); // read analog value (voltage in [V])
float val2 = hExt.pin4.analogReadVoltage(); // read analog value (voltage in [V])
float val3 = hExt.pin5.analogReadVoltage(); // read analog value (voltage in [V])
Serial.printf(“Voltage hSens4.pin1: %f\tRaw data hExt.pin1: %d\r\n”, val1, val2); // send string via USB Serial at 460800
platform.ui.label(“lb_adc0”).setText("%f [V]", val1);
platform.ui.label(“lb_adc1”).setText("%f [V]", val2);
platform.ui.label(“lb_adc2”).setText("%f [V]", val3);
}

ros::Subscriber<geometry_msgs::Twist> sub("/mstx11/cmd_vel", &twistCallback);

void hMain()
{
platform.begin(&RPi);
nh.getHardware()->initWithDevice(&platform.LocalSerial);
nh.initNode();
nh.subscribe(sub);
LED1.on();
while (true)
{
nh.spinOnce();
sys.delay(100);
}
}

/*void hMain()
{
platform.begin(&RPi);
nh.getHardware()->initWithDevice(&platform.LocalSerial);
nh.initNode();
nh.subscribe(sub);
platform.ui.configHandler = cfgHandler;
platform.ui.onKeyEvent = onKeyEvent;
platform.ui.onButtonEvent = onButtonEvent;
platform.ui.setProjectId("@@@PROJECT_ID@@@");

sys.setSysLogDev(&devNull); //turn off sys logs
sys.setLogDev(&Serial);     //default console setup - USB Serial
Serial.init(115200);        //default baudrate for USB Serial is 460800

sys.taskCreate(printfOnConsoleInWebIDE);
for (;;) {
	sys.delay(500); //Sign of life
	printf("\r\nuptime %u", (unsigned int)sys.getRefTime()); //print on default console - USB Serial
	platform.ui.label("lb_up").setText("uptime %u", (unsigned int)sys.getRefTime());
	platform.ui.label("lb_bat").setText("%f [V]", sys.getSupplyVoltage());
	LED2.toggle(); //Sign of life
	checkADC();
	nh.spinOnce();
    sys.delay(100);
}

}*/

Can someone help my with this problem?
If I try to copy the code from ROS tutorial - Converting motion command to motor drive signal, I get the same

multiple definition of `nh’
error

Never mind, my mistake.
I saw that the problem was in ROS.cpp, so I asumed that this was a file opened bij ROS.h. But instead it was a file I created myself from the example. Deleting this ROS.cpp file solved the problem :slight_smile:

1 Like