Publishing transform with rosserial + display in RVIZ?
I'm trying to model a simple helicopter transform with a spinning rotor in RVIZ. I would prefer it to be timestamped into a single topic.
I've been working through the Odom and TimeTF examples in rosserial. I have a base_link that I would like to remain fixed in position but rotate on XYZ with data from an IMU (as the body of a helicopter in flight would behave).
I then have an odom that is translated a fixed, Z distance away that I would like to rotate about Z only, and be fixed to the rotation of base_link (as the spinning rotor on a helicopter would behave).
I have all the arduino code for the IMU and rotation/encoder done. I just can't seem to figure out how to do the above ROS part. The farthest I can get is to have a fixed base_link, + odom transform translated some distance from the body of the helicopter and have the rotor spin using a yaw quaternion (that takes angle position data from my encoder).
Questions:
- Is there a way to make the base link rotate about 3 values from my IMU (x,y,z)?
- While simultaneously having the translated odom transform spinning?
- Further, the above would constitute 4 different readings: (1) accel x, (2) accel y, (3) accel z, encoder position angle.
- Can I also publish these all as individual values to a single topic?
- Can I also publish an infinite amount of other values to this same topic as well under subheadings? Like temperature, gyro x, y, z, etc.?
I've included my arduino ros code progress below. Any help would be immensely appreciated! Thank you.
// libraries
#include <ros.h>
#include <ros/time.h>
#include <tf/transform_broadcaster.h>
#include <tf/tf.h>
ros::NodeHandle nh;
// ros publisher instantiation for Odom & TF
geometry_msgs::TransformStamped t;
tf::TransformBroadcaster broadcaster;
// ros chars
char base_link[] = "/base_link";
char rotor_odom[] = "/rotor_odom";
float encoderAngle;
void setup() {
nh.initNode(); // ros node setup
broadcaster.init(nh); // Odom & transform
}
void rosLoop() {
// tf odom->base_link:
t.header.frame_id = base_link;
t.child_frame_id = rotor_odom;
t.transform.translation.x = 0;
t.transform.translation.y = 0;
t.transform.translation.z = 2;
t.transform.rotation = tf::createQuaternionFromYaw(encoderAngle*3.141592/180);
t.transform.rotation.x = 0.0;
t.transform.rotation.y = 0.0;
broadcaster.sendTransform(t);
t.header.stamp = nh.now();
// spinOnce
nh.spinOnce();
}
Asked by elrosito on 2022-11-08 02:26:44 UTC
Comments