Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ find_package(catkin REQUIRED COMPONENTS
mavros_msgs
nav_msgs
tf
tf2
tf2_ros
tf2_geometry_msgs
cv_bridge
state_controller
Expand Down Expand Up @@ -63,6 +63,7 @@ add_message_files(
Hemisphere.msg
RoboClawStats.msg
ImuSafety.msg
DiffDrive.msg
)

# Generate services in the 'srv' folder
Expand Down Expand Up @@ -134,6 +135,7 @@ add_executable( idk src/arm_drone.cpp )
add_executable( road_detection src/road_detection.cpp )
add_executable(imu_safety src/imu_safety/ImuSafety.cpp)
add_executable(imu_base src/ImuBase/ImuBase.cpp)
add_executable(enc_odom src/EncOdom/EncOdom.cpp)
add_executable(Watchdog src/Watchdog/Watchdog.cpp)

# Specify libraries to link a library or executable target against
Expand All @@ -144,12 +146,14 @@ target_link_libraries( idk ${catkin_LIBRARIES} )
target_link_libraries( road_detection ${OpenCV_LIBS} )
target_link_libraries(imu_safety ${catkin_LIBRARIES})
target_link_libraries(imu_base ${catkin_LIBRARIES})
target_link_libraries(enc_odom ${catkin_LIBRARIES})
target_link_libraries(Watchdog ${catkin_LIBRARIES})

# Add cmake target dependencies of the executable
# same as for the library above
add_dependencies(Hemisphere ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(imu_safety ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(enc_odom ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})


#IF(Qt5Widgets_FOUND)
Expand Down
1 change: 1 addition & 0 deletions launch/localization.launch
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<!-- <node name="hemisphere_tf" pkg="tf" type="static_transform_publisher" args="1.94 0 1.49 0 0 0 50" /> -->
<node name="laser2_to_base" pkg="tf" type="static_transform_publisher" args="2.20 0 1.30 0 1.571 0 /base_link /laser 50" />
<node name="imu_to_base" pkg="tf" type="static_transform_publisher" args = "0 0 0 0 1.571 1.571 /base_link /base_imu 100"/>
<node name="enc_to_base" pkg="tf2_ros" type="static_transform_publisher" args = "0 0 0 0 0 0 /base_link /enc_odom"/>
</launch>
4 changes: 4 additions & 0 deletions msg/DiffDrive.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This represents the distance between the two wheels
float64 wheelbase
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell me what this is

float64 rvel
float64 lvel
38 changes: 38 additions & 0 deletions src/EncOdom/EncOdom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "EncOdom.h"
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>

EncOdom::EncOdom()
: sub(nh.subscribe("diffdrive_raw", 100, &EncOdom::callback, this))
, then(ros::Time::now())
{
transformStamped.header.frame_id = "odom";
transformStamped.child_frame_id = "enc_link";
}

void EncOdom::callback(const gravl::DiffDrive::ConstPtr& msg)
{
const auto now = ros::Time::now();
const auto angularVel = (msg->rvel - msg->lvel) / msg->wheelbase;
const auto tangentialVel = (msg->rvel + msg->lvel) / 2;
const auto dt = (now - then).toSec();

tf2::Quaternion oldOrientation;
tf2::convert(transformStamped.transform.rotation, oldOrientation);
const auto newOrientation = oldOrientation * tf2::Vector3(0, 0, angularVel * dt);
tf2::convert(newOrientation, transformStamped.transform.rotation);

tf2::Vector3 oldTranslation;
tf2::convert(transformStamped.transform.translation, oldTranslation);
const auto deltaPosition = tf2::quatRotate(newOrientation, tf2::Vector3(0, 0, tangentialVel * dt));
tf2::convert(oldTranslation + deltaPosition, transformStamped.transform.translation);

br.sendTransform(transformStamped);
then = now;
}

int main(int argc, char** argv)
{
ros::init(argc, argv, "enc_odom");
EncOdom encOdom;
ros::spin();
}
19 changes: 19 additions & 0 deletions src/EncOdom/EncOdom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <gravl/DiffDrive.h>
#include <tf2_ros/transform_broadcaster.h>

class EncOdom
{
public:
EncOdom();

private:
void callback(const gravl::DiffDrive::ConstPtr& msg);

ros::NodeHandle nh;
tf2_ros::TransformBroadcaster br;
ros::Subscriber sub;
geometry_msgs::TransformStamped transformStamped;
ros::Time then;
};