When I compile this my sketch with this tb3_exentsions.cpp
:
#include "turtlebot3_core_config.h"
Servo servo; // create servo object to control a servo
void initServo(ros::NodeHandle nh)
{
servo.attach(9); // attaches the servo on pin 9 to the servo object
}
I get an error message that the Servo class is not defined. When I add include <Servo.h>
I get an avalanche of errors. Here are the first few. They all look generally similar.
sketch/turtlebot3_core_hack.ino.cpp.o:(.bss.battery_state+0x0): multiple definition of `battery_state'
sketch/tb3_extensions.cpp.o:(.bss.battery_state+0x0): first defined here
sketch/turtlebot3_core_hack.ino.cpp.o: In function `ArduinoHardware::time()':
/Users/pitosalas/Documents/Arduino/turtlebot3_core_hack/turtlebot3_core_hack.ino:354: multiple definition of `setup_end'
sketch/tb3_extensions.cpp.o:/Users/pitosalas/Library/Arduino15/packages/OpenCR/hardware/OpenCR/1.4.19/libraries/turtlebot3_ros_lib/std_msgs/Header.h:33: first defined here
sketch/turtlebot3_core_hack.ino.cpp.o: In function `ArduinoHardware::time()':
/Users/pitosalas/Documents/Arduino/turtlebot3_core_hack/turtlebot3_core_hack.ino:354: multiple definition of `odom_vel'
sketch/tb3_extensions.cpp.o:/Users/pitosalas/Library/Arduino15/packages/OpenCR/hardware/OpenCR/1.4.19/libraries/turtlebot3_ros_lib/std_msgs/Header.h:33: first defined here
sketch/turtlebot3_core_hack.ino.cpp.o: In function `ArduinoHardware::time()':
The rest of the sketch has three other files:
-
turtlebot_core_hack.ino
- which importstrutlebot3_core_config.h
-
turtlebot3_core_config.h
- which imports many things includingtb3_extensions.h
andturtlebot3_burger.h
-
turtlebot3_burger.h
- which imports nothing
Why does including Servo.h
in tb3_extensions.cpp
cause all the multiple definition errors?