Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

segwayrmp.h

Go to the documentation of this file.
00001 /*
00002  *  Player - One Hell of a Robot Server
00003  *  Copyright (C) 2003  John Sweeney & Brian Gerkey
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  */
00020 
00021 #include "canio.h"
00022 #include "canio_kvaser.h"
00023 #include "player.h"
00024 #include "device.h"
00025 #include "configfile.h"
00026 
00027 
00028 // Forward declarations
00029 class rmp_frame_t;
00030 
00031 
00032 // Driver for robotic Segway
00033 class SegwayRMP : public Driver
00034 {
00035   public: 
00036     // Constructors etc
00037     SegwayRMP(ConfigFile* cf, int section);
00038     ~SegwayRMP();
00039 
00040     // Setup/shutdown routines.
00041     virtual int Setup();
00042     virtual int Shutdown();
00043 
00044   protected:
00045 
00046     // Supported interfaces
00047     player_device_id_t position_id;
00048     player_position_data_t position_data;
00049 
00050     player_device_id_t position3d_id;
00051     player_position3d_data_t position3d_data;
00052   
00053     player_device_id_t power_id;
00054     player_power_data_t power_data;
00055 
00056   private:
00057 
00058     const char* portname;
00059     const char* caniotype;
00060 
00061     int timeout_counter;
00062 
00063     int max_xspeed, max_yawspeed;
00064 
00065     bool firstread;
00066 
00067     DualCANIO *canio;
00068 
00069     int16_t last_xspeed, last_yawspeed;
00070 
00071     // Flag set if motors can be enabled (i.e., enable them to be
00072     // enabled).  Set by a config request.
00073     bool motor_allow_enable;
00074 
00075     // Flag set if motors are currently enabled
00076     bool motor_enabled;
00077 
00078     // For handling rollover
00079     uint32_t last_raw_yaw, last_raw_left, last_raw_right, last_raw_foreaft;
00080 
00081     // Odometry calculation
00082     double odom_x, odom_y, odom_yaw;
00083 
00084     // helper to handle config requests
00085     int HandlePositionConfig(void* client, unsigned char* buffer, size_t len);
00086 
00087     // helper to handle config requests
00088     int HandlePosition3DConfig(void* client, unsigned char* buffer, size_t len);
00089 
00090     // helper to read a cycle of data from the RMP
00091     int Read();
00092     
00093     // Calculate the difference between two raw counter values, taking care
00094     // of rollover.
00095     int Diff(uint32_t from, uint32_t to, bool first);
00096 
00097     // helper to write a packet
00098     int Write(CanPacket& pkt);
00099 
00100     // Main function for device thread.
00101     virtual void Main();
00102 
00103     // helper to create a status command packet from the given args
00104     void MakeStatusCommand(CanPacket* pkt, uint16_t cmd, uint16_t val);
00105 
00106     // helper to take a player command and turn it into a CAN command packet
00107     void MakeVelocityCommand(CanPacket* pkt, int32_t xspeed, int32_t yawspeed);
00108     
00109     void MakeShutdownCommand(CanPacket* pkt);
00110 
00111     void UpdateData(rmp_frame_t *);
00112 };
00113 
00114 

Generated on Tue May 3 14:15:36 2005 for Player by doxygen 1.3.6