.. _program_listing_file__tmp_ws_src_raspimouse2_raspimouse_include_raspimouse_raspimouse_component.hpp: Program Listing for File raspimouse_component.hpp ================================================= |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/raspimouse2/raspimouse/include/raspimouse/raspimouse_component.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp // Copyright 2018 Geoffrey Biggs, AIST // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef RASPIMOUSE__RASPIMOUSE_COMPONENT_HPP_ #define RASPIMOUSE__RASPIMOUSE_COMPONENT_HPP_ #if __cplusplus extern "C" { #endif // The below macros are taken from https://gcc.gnu.org/wiki/Visibility and from // demos/composition/include/composition/visibility_control.h at https://github.com/ros2/demos #if defined _WIN32 || defined __CYGWIN__ #ifdef __GNUC__ #define RASPIMOUSE_EXPORT __attribute__ ((dllexport)) #define RASPIMOUSE_IMPORT __attribute__ ((dllimport)) #else #define RASPIMOUSE_EXPORT __declspec(dllexport) #define RASPIMOUSE_IMPORT __declspec(dllimport) #endif #ifdef RASPIMOUSE_BUILDING_DLL #define RASPIMOUSE_PUBLIC RASPIMOUSE_EXPORT #else #define RASPIMOUSE_PUBLIC RASPIMOUSE_IMPORT #endif #define RASPIMOUSE_PUBLIC_TYPE RASPIMOUSE_PUBLIC #define RASPIMOUSE_LOCAL #else #define RASPIMOUSE_EXPORT __attribute__ ((visibility("default"))) #define RASPIMOUSE_IMPORT #if __GNUC__ >= 4 #define RASPIMOUSE_PUBLIC __attribute__ ((visibility("default"))) #define RASPIMOUSE_LOCAL __attribute__ ((visibility("hidden"))) #else #define RASPIMOUSE_PUBLIC #define RASPIMOUSE_LOCAL #endif #define RASPIMOUSE_PUBLIC_TYPE #endif #if __cplusplus } // extern "C" #endif #include #include #include #include #include #include #include #include #include #include #include #include #include namespace raspimouse { class Raspimouse : public rclcpp_lifecycle::LifecycleNode { public: RASPIMOUSE_PUBLIC explicit Raspimouse(const rclcpp::NodeOptions & options); ~Raspimouse(void); private: rclcpp::Clock ros_clock_; std::shared_ptr> odom_pub_; nav_msgs::msg::Odometry odom_; std::shared_ptr odom_transform_broadcaster_; geometry_msgs::msg::TransformStamped odom_transform_; rclcpp::TimerBase::SharedPtr odom_timer_; rclcpp::Time last_odom_time_; double linear_velocity_; double angular_velocity_; double odom_theta_; bool use_pulse_counters_; int last_pulse_count_left_; int last_pulse_count_right_; rclcpp::Subscription::SharedPtr velocity_sub_; rclcpp::Service::SharedPtr power_service_; rclcpp::TimerBase::SharedPtr watchdog_timer_; std::shared_ptr power_control_; std::shared_ptr left_motor_control_; std::shared_ptr right_motor_control_; std::shared_ptr> switches_pub_; std::shared_ptr> light_sensors_pub_; rclcpp::Subscription::SharedPtr leds_sub_; rclcpp::Subscription::SharedPtr buzzer_sub_; rclcpp::TimerBase::SharedPtr switches_timer_; rclcpp::TimerBase::SharedPtr light_sensors_timer_; std::shared_ptr led0_output_; std::shared_ptr led1_output_; std::shared_ptr led2_output_; std::shared_ptr led3_output_; std::shared_ptr buzzer_output_; rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_configure(const rclcpp_lifecycle::State &); rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_activate(const rclcpp_lifecycle::State &); rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_deactivate(const rclcpp_lifecycle::State &); rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_cleanup(const rclcpp_lifecycle::State &); rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn on_shutdown(const rclcpp_lifecycle::State &); void release_pointers(); void publish_odometry(); void publish_switches(); void publish_light_sensors(); void velocity_command(const geometry_msgs::msg::Twist::SharedPtr msg); void leds_command(const raspimouse_msgs::msg::Leds::SharedPtr msg); void buzzer_command(const std_msgs::msg::Int16::SharedPtr msg); void handle_motor_power( const std::shared_ptr request_header, const std::shared_ptr request, const std::shared_ptr response); void watchdog(); void set_motor_power(bool value); void stop_motors(); void calculate_odometry_from_pulse_counts(double & x, double & y, double & theta); void estimate_odometry(double & x, double & y, double & theta); }; } // namespace raspimouse #endif // RASPIMOUSE__RASPIMOUSE_COMPONENT_HPP_