Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef P2OS_DRIVER__P2OS_HPP_
00023 #define P2OS_DRIVER__P2OS_HPP_
00024 #include <pthread.h>
00025 #include <sys/time.h>
00026
00027 #include <ros/ros.h>
00028 #include <nav_msgs/Odometry.h>
00029 #include <geometry_msgs/Twist.h>
00030 #include <tf/transform_broadcaster.h>
00031 #include <p2os_msgs/BatteryState.h>
00032 #include <p2os_msgs/MotorState.h>
00033 #include <p2os_msgs/GripperState.h>
00034 #include <p2os_msgs/SonarArray.h>
00035 #include <p2os_msgs/DIO.h>
00036 #include <p2os_msgs/AIO.h>
00037
00038 #include <diagnostic_updater/publisher.h>
00039 #include <diagnostic_updater/diagnostic_updater.h>
00040
00041 #include <p2os_driver/packet.hpp>
00042 #include <p2os_driver/robot_params.hpp>
00043
00044 #include <iostream>
00045 #include <cstring>
00046 #include <string>
00047
00053 typedef struct ros_p2os_data
00054 {
00056 nav_msgs::Odometry position;
00058 p2os_msgs::BatteryState batt;
00060 p2os_msgs::MotorState motors;
00062 p2os_msgs::GripperState gripper;
00064 p2os_msgs::SonarArray sonar;
00066 p2os_msgs::DIO dio;
00068 p2os_msgs::AIO aio;
00070 geometry_msgs::TransformStamped odom_trans;
00071 } ros_p2os_data_t;
00072
00073
00074 #include "sip.hpp"
00075 #include "kinecalc.hpp"
00076
00077 #include "p2os_ptz.hpp"
00078
00079 class SIP;
00080
00081
00082
00083 class P2OSNode
00084 {
00091 public:
00092 explicit P2OSNode(ros::NodeHandle n);
00093 virtual ~P2OSNode();
00094
00095 public:
00097 int Setup();
00099 int Shutdown();
00100
00101 int SendReceive(P2OSPacket * pkt, bool publish_data = true);
00102
00103 void updateDiagnostics();
00104
00105 void ResetRawPositions();
00106 void ToggleSonarPower(unsigned char val);
00107 void ToggleMotorPower(unsigned char val);
00108 void StandardSIPPutData(ros::Time ts);
00109
00110 inline double TicksToDegrees(int joint, unsigned char ticks);
00111 inline unsigned char DegreesToTicks(int joint, double degrees);
00112 inline double TicksToRadians(int joint, unsigned char ticks);
00113 inline unsigned char RadiansToTicks(int joint, double rads);
00114 inline double RadsPerSectoSecsPerTick(int joint, double speed);
00115 inline double SecsPerTicktoRadsPerSec(int joint, double secs);
00116
00117 void SendPulse(void);
00118
00119 void check_and_set_vel();
00120 void cmdvel_cb(const geometry_msgs::TwistConstPtr &);
00121
00122 void check_and_set_motor_state();
00123 void cmdmotor_state(const p2os_msgs::MotorStateConstPtr &);
00124
00125 void check_and_set_gripper_state();
00126 void gripperCallback(const p2os_msgs::GripperStateConstPtr & msg);
00127 double get_pulse() {return pulse;}
00128
00129
00130 void check_voltage(diagnostic_updater::DiagnosticStatusWrapper & stat);
00131 void check_stall(diagnostic_updater::DiagnosticStatusWrapper & stat);
00132
00133 protected:
00135 ros::NodeHandle n;
00137 ros::NodeHandle nh_private;
00138
00139 diagnostic_updater::Updater diagnostic_;
00140
00141 diagnostic_updater::DiagnosedPublisher<p2os_msgs::BatteryState> batt_pub_;
00142 ros::Publisher mstate_pub_, grip_state_pub_,
00143 ptz_state_pub_, sonar_pub_, aio_pub_, dio_pub_;
00144 ros::Publisher pose_pub_;
00145 ros::Subscriber cmdvel_sub_, cmdmstate_sub_, gripper_sub_, ptz_cmd_sub_;
00146
00147 tf::TransformBroadcaster odom_broadcaster;
00148 ros::Time veltime;
00149
00150 SIP * sippacket;
00151 std::string psos_serial_port;
00152 std::string psos_tcp_host;
00153 std::string odom_frame_id;
00154 std::string base_link_frame_id;
00155 int psos_fd;
00156 bool psos_use_tcp;
00157 int psos_tcp_port;
00158 bool vel_dirty, motor_dirty;
00159 bool gripper_dirty_ = false;
00160 int param_idx;
00161
00162 int rot_kp, rot_kv, rot_ki, trans_kp, trans_kv, trans_ki;
00163
00165 int bumpstall;
00167 int joystick;
00169 int direct_wheel_vel_control;
00170 int radio_modemp;
00171
00173 int motor_max_speed;
00175 int motor_max_turnspeed;
00177 int16_t motor_max_trans_accel;
00179 int16_t motor_max_trans_decel;
00181 int16_t motor_max_rot_accel;
00183 int16_t motor_max_rot_decel;
00185 double pulse;
00186 double desired_freq;
00188 double lastPulseTime;
00190 bool use_sonar_;
00191
00192 P2OSPtz ptz_;
00193
00194 public:
00196 geometry_msgs::Twist cmdvel_;
00198 p2os_msgs::MotorState cmdmotor_state_;
00200 p2os_msgs::GripperState gripper_state_;
00202 ros_p2os_data_t p2os_data;
00203 };
00204
00205 #endif // P2OS_DRIVER__P2OS_HPP_