omnix.h
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <tf/transform_broadcaster.h>
00003 #include <geometry_msgs/Twist.h>
00004 #include <sensor_msgs/Joy.h>
00005 #include <nav_msgs/Odometry.h>
00006 #include <omnix/buttons.h>
00007 #include <omnix/EngageBrake.h>
00008 #include <omnix/ReleaseBrake.h>
00009 #include <omnix/DisableJoystick.h>
00010 #include <omnix/EnableJoystick.h>
00011 //#include <omnix/WheelPos.h>
00012 
00013 #include <sys/socket.h>
00014 #include <sys/types.h>
00015 #include <netinet/in.h>
00016 #include <arpa/inet.h>
00017 #include <netdb.h>
00018 #include <stdio.h>
00019 #include <unistd.h>
00020 #include <errno.h>
00021 #include <string.h>
00022 
00023 class OmnixNode{
00024  private:
00025   ros::Time last_vel_cmd_recd;
00026   ros::Time last_vel_cmd_sent;
00027   ros::Time last_estop_recd;
00028 
00029   geometry_msgs::Twist* last_vel_cmd;
00030 
00031   ros::ServiceServer engage_brake_service_;
00032   ros::ServiceServer disengage_brake_service_;
00033   ros::ServiceServer get_joint_position_service_;
00034   ros::ServiceServer disable_joystick_service_;
00035 
00036   std::string hostname;
00037   int portno;
00038   int sock;
00039   struct hostent *host;
00040   struct sockaddr_in server_addr;
00041   int server_addr_len;
00042 
00043   int portno_rec;
00044   int sock_rec;
00045   struct hostent *host_rec;
00046   struct sockaddr_in server_addr_rec;
00047   int server_addr_rec_len;
00048   struct sockaddr_in server_addr_rec_other;
00049   int server_addr_rec_other_len;
00050 
00051   int counter;
00052 
00053   bool emergency_stop;
00054   bool first_write;
00055   bool brake_engaged;
00056   bool joystick_controlled;
00057   bool recv_odom;
00058   bool verbose;
00059   bool open_rec_socket;
00060   char rec_buf[1024];
00061   int rec_buf_size;
00062 
00063   //odom info
00064   double odom_x, odom_y, odom_yaw;
00065   double prev_j1, prev_j2, prev_j3, prev_j4;
00066   double vx, vy, vt;
00067   ros::Time prev_time;
00068 
00069   //Commands
00070   std::string DisableJoystickCommand;
00071   std::string EnableJoystickCommand;
00072   std::string EnableRobotControlCommand;//TODO: NYI (not needed)
00073   std::string DisableRobotControlCommand;
00074   std::string SetVelocityCommand;
00075   std::string SetJointVelocitiesCommand;
00076   std::string GetJointPositionCommand;
00077   std::string EngageBrakeCommand;
00078   std::string ReleaseBrakeCommand;
00079   std::string SetBlinkPatternCommand;//TODO: NYI
00080 
00081  public:
00082   ros::NodeHandle n_;
00083   tf::TransformBroadcaster tf_;
00084   ros::Subscriber cmd_vel_sub_;
00085   ros::Subscriber joy_sub_;
00086   ros::Timer estop_timer_;
00087   ros::Timer read_timer_;
00088   ros::Duration estop_timeout_;
00089   ros::Publisher odom_pub_;
00090   ros::Publisher wheel_pos_pub_;
00091 
00092   OmnixNode();
00093   ~OmnixNode();
00094   void openOmnixSocket();
00095   void openOmnixSocketRec();
00096   void closeOmnixSocket();
00097   bool sendCommand(const std::string& cmd);
00098   void sendGetJointPosition();
00099   void cmdvelCallback(const geometry_msgs::Twist::ConstPtr& cmd_vel);
00100   bool EngageBrakeCallback(omnix::EngageBrake::Request &req, omnix::EngageBrake::Response &res);
00101   bool ReleaseBrakeCallback(omnix::ReleaseBrake::Request &req, omnix::ReleaseBrake::Response &res);
00102   bool DisableJoystickCallback(omnix::DisableJoystick::Request &req, omnix::DisableJoystick::Response &res);
00103   bool EnableJoystickCallback(omnix::EnableJoystick::Request &req, omnix::EnableJoystickResponse &res);
00104   void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
00105   void timerCallback(const ros::TimerEvent& e);
00106   void readTimerCallback(const ros::TimerEvent& e);
00107   bool recvResponse(bool blocking=true);
00108   bool peekForNewline();
00109 
00110   void initCommands()
00111   {
00112     DisableJoystickCommand = "DJS";
00113     EnableJoystickCommand = "EJS";
00114     EnableRobotControlCommand = "ERC";
00115     DisableRobotControlCommand = "DRC";
00116     SetVelocityCommand = "SOV";
00117     SetJointVelocitiesCommand = "SJV";
00118     GetJointPositionCommand = "GJP";
00119     EngageBrakeCommand = "EBK";
00120     ReleaseBrakeCommand = "RBK";
00121     SetBlinkPatternCommand = "SBP";
00122   }
00123 
00124 };


omnix
Author(s): Alexander J Trevor
autogenerated on Wed Nov 27 2013 12:06:10