p2os.hpp
Go to the documentation of this file.
1 /*
2  * P2OS for ROS
3  * Copyright (C) 2009 David Feil-Seifer, Brian Gerkey, Kasper Stoy,
4  * Richard Vaughan, & Andrew Howard
5  * Copyright (C) 2018 Hunter L. Allen
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22 #ifndef P2OS_DRIVER__P2OS_HPP_
23 #define P2OS_DRIVER__P2OS_HPP_
24 #include <pthread.h>
25 #include <sys/time.h>
26 
27 #include <ros/ros.h>
28 #include <nav_msgs/Odometry.h>
29 #include <geometry_msgs/Twist.h>
31 #include <p2os_msgs/BatteryState.h>
32 #include <p2os_msgs/MotorState.h>
33 #include <p2os_msgs/GripperState.h>
34 #include <p2os_msgs/SonarArray.h>
35 #include <p2os_msgs/DIO.h>
36 #include <p2os_msgs/AIO.h>
37 
40 
41 #include <p2os_driver/packet.hpp>
43 
44 #include <iostream>
45 #include <cstring>
46 #include <string>
47 
53 typedef struct ros_p2os_data
54 {
56  nav_msgs::Odometry position;
58  p2os_msgs::BatteryState batt;
60  p2os_msgs::MotorState motors;
62  p2os_msgs::GripperState gripper;
64  p2os_msgs::SonarArray sonar;
66  p2os_msgs::DIO dio;
68  p2os_msgs::AIO aio;
70  geometry_msgs::TransformStamped odom_trans;
72 
73 // this is here because we need the above typedef's before including it.
74 #include "sip.hpp"
75 #include "kinecalc.hpp"
76 
77 #include "p2os_ptz.hpp"
78 
79 class SIP;
80 
81 // Forward declaration of the KineCalc_Base class declared in kinecalc_base.h
82 
83 class P2OSNode
84 {
91 public:
92  explicit P2OSNode(ros::NodeHandle n);
93  virtual ~P2OSNode();
94 
95 public:
97  int Setup();
99  int Shutdown();
100 
101  int SendReceive(P2OSPacket * pkt, bool publish_data = true);
102 
103  void updateDiagnostics();
104 
105  void ResetRawPositions();
106  void ToggleSonarPower(unsigned char val);
107  void ToggleMotorPower(unsigned char val);
108  void StandardSIPPutData(ros::Time ts);
109 
110  inline double TicksToDegrees(int joint, unsigned char ticks);
111  inline unsigned char DegreesToTicks(int joint, double degrees);
112  inline double TicksToRadians(int joint, unsigned char ticks);
113  inline unsigned char RadiansToTicks(int joint, double rads);
114  inline double RadsPerSectoSecsPerTick(int joint, double speed);
115  inline double SecsPerTicktoRadsPerSec(int joint, double secs);
116 
117  void SendPulse(void);
118 
119  void check_and_set_vel();
120  void cmdvel_cb(const geometry_msgs::TwistConstPtr &);
121 
122  void check_and_set_motor_state();
123  void cmdmotor_state(const p2os_msgs::MotorStateConstPtr &);
124 
125  void check_and_set_gripper_state();
126  void gripperCallback(const p2os_msgs::GripperStateConstPtr & msg);
127  double get_pulse() {return pulse;}
128 
129  // diagnostic messages
130  void check_voltage(diagnostic_updater::DiagnosticStatusWrapper & stat);
131  void check_stall(diagnostic_updater::DiagnosticStatusWrapper & stat);
132 
133 protected:
138 
140 
142  ros::Publisher mstate_pub_, grip_state_pub_,
143  ptz_state_pub_, sonar_pub_, aio_pub_, dio_pub_;
145  ros::Subscriber cmdvel_sub_, cmdmstate_sub_, gripper_sub_, ptz_cmd_sub_;
146 
149 
151  std::string psos_serial_port;
152  std::string psos_tcp_host;
153  std::string odom_frame_id;
154  std::string base_link_frame_id;
155  int psos_fd;
158  bool vel_dirty, motor_dirty;
159  bool gripper_dirty_ = false;
161  // PID settings
162  int rot_kp, rot_kv, rot_ki, trans_kp, trans_kv, trans_ki;
163 
165  int bumpstall; // should we change the bumper-stall behavior?
167  int joystick;
171 
185  double pulse;
186  double desired_freq;
191 
193 
194 public:
196  geometry_msgs::Twist cmdvel_;
198  p2os_msgs::MotorState cmdmotor_state_;
200  p2os_msgs::GripperState gripper_state_;
203 };
204 
205 #endif // P2OS_DRIVER__P2OS_HPP_
std::string psos_tcp_host
Definition: p2os.hpp:152
diagnostic_updater::Updater diagnostic_
Definition: p2os.hpp:139
msg
Container struct.
Definition: p2os.hpp:53
int motor_max_speed
Maximum motor speed in Meters per second.
Definition: p2os.hpp:173
int trans_kv
Definition: p2os.hpp:162
double get_pulse()
Definition: p2os.hpp:127
p2os_msgs::MotorState cmdmotor_state_
Motor state publisher.
Definition: p2os.hpp:198
p2os_msgs::SonarArray sonar
Container for sonar data.
Definition: p2os.hpp:64
int psos_tcp_port
Definition: p2os.hpp:157
bool use_sonar_
Use the sonar array?
Definition: p2os.hpp:190
SIP * sippacket
Definition: p2os.hpp:150
int16_t motor_max_rot_decel
Minimum rotational acceleration in Meters per second per second.
Definition: p2os.hpp:183
struct ros_p2os_data ros_p2os_data_t
Container struct.
p2os_msgs::AIO aio
Analog In/Out.
Definition: p2os.hpp:68
int16_t motor_max_trans_decel
Minimum translational acceleration in Meters per second per second.
Definition: p2os.hpp:179
ros::NodeHandle n
Node Handler used for publication of data.
Definition: p2os.hpp:135
std::string psos_serial_port
Definition: p2os.hpp:151
int joystick
Use Joystick?
Definition: p2os.hpp:167
std::string base_link_frame_id
Definition: p2os.hpp:154
p2os_msgs::GripperState gripper
Provides the state of the gripper.
Definition: p2os.hpp:62
geometry_msgs::TransformStamped odom_trans
Transformed odometry frame.
Definition: p2os.hpp:70
ros::Publisher sonar_pub_
Definition: p2os.hpp:142
tf::TransformBroadcaster odom_broadcaster
Definition: p2os.hpp:147
int16_t motor_max_rot_accel
Maximum rotational acceleration in radians per second per second.
Definition: p2os.hpp:181
diagnostic_updater::DiagnosedPublisher< p2os_msgs::BatteryState > batt_pub_
Definition: p2os.hpp:141
int16_t motor_max_trans_accel
Maximum translational acceleration in Meters per second per second.
Definition: p2os.hpp:177
int bumpstall
Stall I hit a wall?
Definition: p2os.hpp:165
double pulse
Pulse time.
Definition: p2os.hpp:185
p2os_msgs::GripperState gripper_state_
Gripper state publisher.
Definition: p2os.hpp:200
double desired_freq
Definition: p2os.hpp:186
bool vel_dirty
Definition: p2os.hpp:158
bool psos_use_tcp
Definition: p2os.hpp:156
ros::Time veltime
Definition: p2os.hpp:148
ros::Subscriber ptz_cmd_sub_
Definition: p2os.hpp:145
P2OSPtz ptz_
Definition: p2os.hpp:192
p2os_msgs::BatteryState batt
Provides the battery voltage.
Definition: p2os.hpp:58
int motor_max_turnspeed
Maximum turn speed in radians per second.
Definition: p2os.hpp:175
double lastPulseTime
Last time the node received or sent a pulse.
Definition: p2os.hpp:188
Definition: sip.hpp:55
int psos_fd
Definition: p2os.hpp:155
int param_idx
Definition: p2os.hpp:160
std::string odom_frame_id
Definition: p2os.hpp:153
ros::NodeHandle nh_private
Node Handler used for private data publication.
Definition: p2os.hpp:137
ros_p2os_data_t p2os_data
sensor data container
Definition: p2os.hpp:202
geometry_msgs::Twist cmdvel_
Command Velocity subscriber.
Definition: p2os.hpp:196
p2os_msgs::MotorState motors
Provides the state of the motors (enabled or disabled)
Definition: p2os.hpp:60
int radio_modemp
Definition: p2os.hpp:170
nav_msgs::Odometry position
Provides the position of the robot.
Definition: p2os.hpp:56
int direct_wheel_vel_control
Control wheel velocities individually?
Definition: p2os.hpp:169
p2os_msgs::DIO dio
Digital In/Out.
Definition: p2os.hpp:66
ros::Publisher pose_pub_
Definition: p2os.hpp:144


p2os_driver
Author(s): Hunter L. Allen , David Feil-Seifer , Aris Synodinos , Brian Gerkey, Kasper Stoy, Richard Vaughan, Andrew Howard, Tucker Hermans, ActivMedia Robotics LLC, MobileRobots Inc.
autogenerated on Sat Jun 20 2020 03:29:42