Hi guys,
I am trying to publish tf and odom with teensy 4.1 from my robot. I am getting an error from rosserial_python node saying the following. However if I publish tf alone it's working perfectly fine.
[ERROR] [1689103096.510274]: Tried to publish before configured, topic id 126
I am posting the code below:
include
include
include
include <tf/transform_broadcaster.h>
include <geometry_msgs/TransformStamped.h>
include <geometry_msgs/Twist.h>
include <geometry_msgs/PoseWithCovarianceStamped.h>
Hi guys, I am trying to publish tf and odom with teensy 4.1 from my robot. I am getting an error from rosserial_python node saying the following. However if I publish tf alone it's working perfectly fine.
[ERROR] [1689103096.510274]: Tried to publish before configured, topic id 126
I am posting the code below:
include
include
include
include <tf/transform_broadcaster.h>
include <geometry_msgs/TransformStamped.h>
include <geometry_msgs/Twist.h>
include <geometry_msgs/PoseWithCovarianceStamped.h>
include <nav_msgs/Odometry.h>
include <geometry_msgs/Vector3.h>
include <tf/tf.h>
include <ros/time.h>
define IN1 8
define IN2 6
define PWM1 7 //LEFT
define IN3 9
define IN4 11
define PWM2 10 //RIGHT
double Pk = 50; double Ik = 80; double Dk = 0.3; double Pk1 = 50; double Ik1 = 80; double Dk1 = 0.3;
double theta = 0; char base_link[] = "/base_link"; char odom[] = "/odom";
float demand1, demand2, demandx, demandz, LeftOutput, RightOutput;
ros::NodeHandle nh; geometry_msgs::TransformStamped t; nav_msgs::Odometry odom_msg; ros::Publisher odom_pub("odom", &odom_msg); tf::TransformBroadcaster broadcaster;
void onTwist(const geometry_msgs::Twist& msg) { demandx = msg.linear.x; demandz = msg.angular.z; }
ros::Subscriber sub("cmd_vel", onTwist);
double Setpoint, Input, Output, Outputa; PID PID1(&Input, &Output, &Setpoint, Pk, Ik, Dk, DIRECT); double Setpoint1, Input1, Output1, Outputa1; PID PID2(&Input1, &Output1, &Setpoint1, Pk1, Ik1, Dk1, DIRECT);
Encoder knobLeft(5, 4); Encoder knobRight(2, 3); double currentMillis, previousMillis, Interval;
unsigned long previousTime = 0; const unsigned long loopInterval = 10; // 10 milliseconds
void setup() {
PID1.SetMode(AUTOMATIC); PID1.SetOutputLimits(-255, 255); PID1.SetSampleTime(10); PID2.SetMode(AUTOMATIC); PID2.SetOutputLimits(-255, 255); PID2.SetSampleTime(10); pinMode(IN4, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN1, OUTPUT); pinMode(PWM2, OUTPUT); pinMode(PWM1, OUTPUT); nh.initNode();
nh.subscribe(sub); nh.advertise(odom_pub); broadcaster.init(nh); }
long positionLeft = 0; long positionRight = 0; double distx = 0; double disty = 0; double deltaX = 0; double deltaY = 0; int timee = 0; double pos_total_mm = 0; float RPMLeftPrev = 0; float LeftFilt = 0;
float RPMRightPrev = 0; float RightFilt = 0; void loop() { nh.spinOnce(); currentMillis = millis(); if (currentMillis - previousMillis > 10) { Interval = currentMillis - previousMillis; double newLeft, newRight, LeftDiff, RightDiff, LeftDiffmm, RightDiffmm, pos_average_mm_diff;
} }