From: <th...@us...> - 2009-01-11 18:48:04
|
Revision: 7266 http://playerstage.svn.sourceforge.net/playerstage/?rev=7266&view=rev Author: thjc Date: 2009-01-11 18:48:00 +0000 (Sun, 11 Jan 2009) Log Message: ----------- Applied patch 2303195: joystick interface expansion Also re enables the joystick proxies Modified Paths: -------------- code/player/trunk/client_libs/libplayerc/CMakeLists.txt code/player/trunk/client_libs/libplayerc/dev_joystick.c code/player/trunk/client_libs/libplayerc/playerc.h code/player/trunk/client_libs/libplayerc++/CMakeLists.txt code/player/trunk/client_libs/libplayerc++/playerc++.h code/player/trunk/libplayercore/interfaces/049_joystick.def code/player/trunk/server/drivers/joystick/linuxjoy.cc Added Paths: ----------- code/player/trunk/client_libs/libplayerc++/joystickproxy.cc Modified: code/player/trunk/client_libs/libplayerc/CMakeLists.txt =================================================================== --- code/player/trunk/client_libs/libplayerc/CMakeLists.txt 2009-01-11 18:43:03 UTC (rev 7265) +++ code/player/trunk/client_libs/libplayerc/CMakeLists.txt 2009-01-11 18:48:00 UTC (rev 7266) @@ -27,6 +27,7 @@ dev_health.c dev_imu.c dev_ir.c + dev_joystick.c dev_laser.c dev_limb.c dev_localize.c Modified: code/player/trunk/client_libs/libplayerc/dev_joystick.c =================================================================== --- code/player/trunk/client_libs/libplayerc/dev_joystick.c 2009-01-11 18:43:03 UTC (rev 7265) +++ code/player/trunk/client_libs/libplayerc/dev_joystick.c 2009-01-11 18:48:00 UTC (rev 7266) @@ -1,4 +1,4 @@ -/* +/* * libplayerc : a Player client library * Copyright (C) Andrew Howard 2002-2003 * @@ -20,8 +20,8 @@ /* * Player - One Hell of a Robot Server * Copyright (C) Andrew Howard 2003 - * * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -37,19 +37,28 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*************************************************************************** - * Desc: Joystick device proxy + * Desc: joystick proxy. * Author: Andrew Howard - * Date: 13 May 2002 + * Date: 26 May 2002 * CVS: $Id$ **************************************************************************/ +#if HAVE_CONFIG_H + #include "config.h" +#endif #include <math.h> #include <stdlib.h> #include <string.h> +#include <netinet/in.h> #include "playerc.h" #include "error.h" +// Local declarations +void playerc_joystick_putmsg(playerc_joystick_t *device, + player_msghdr_t *header, + player_joystick_data_t *data, + size_t len); // Create a new joystick proxy playerc_joystick_t *playerc_joystick_create(playerc_client_t *client, int index) @@ -59,9 +68,8 @@ device = malloc(sizeof(playerc_joystick_t)); memset(device, 0, sizeof(playerc_joystick_t)); playerc_device_init(&device->info, client, PLAYER_JOYSTICK_CODE, index, - (playerc_putdata_fn_t) playerc_joystick_putdata,NULL,NULL); + (playerc_putmsg_fn_t) playerc_joystick_putmsg); - return device; } @@ -71,8 +79,6 @@ { playerc_device_term(&device->info); free(device); - - return; } @@ -91,13 +97,26 @@ // Process incoming data -void playerc_joystick_putdata(playerc_joystick_t *device, player_msghdr_t *header, - player_joystick_data_t *data, size_t len) +void playerc_joystick_putmsg(playerc_joystick_t *device, player_msghdr_t *header, + player_joystick_data_t *data, size_t len) { - device->px = (double) (int16_t) ntohs(data->xpos) / (double) (int16_t) ntohs(data->xscale); - device->py = (double) (int16_t) ntohs(data->ypos) / (double) (int16_t) ntohs(data->yscale); - device->buttons = ntohs(data->buttons); - + int i; + if((header->type == PLAYER_MSGTYPE_DATA) && + (header->subtype == PLAYER_JOYSTICK_DATA_STATE)) + { + + device->buttons = data->buttons; + device->axes_count = data->axes_count; + for (i = 0; i < data->axes_count ; i++) + device->pos[i] = data->pos[i]; + + + } + else + PLAYERC_WARN2("skipping joystick message with unknown type/subtype: %s/%d\n", + msgtype_to_str(header->type), header->subtype); return; } + + Modified: code/player/trunk/client_libs/libplayerc/playerc.h =================================================================== --- code/player/trunk/client_libs/libplayerc/playerc.h 2009-01-11 18:43:03 UTC (rev 7265) +++ code/player/trunk/client_libs/libplayerc/playerc.h 2009-01-11 18:48:00 UTC (rev 7266) @@ -51,7 +51,7 @@ #ifndef PLAYERC_H #define PLAYERC_H -#include <netinet/in.h> // need this for struct sockaddr_in +#include <netinet/in.h> /* need this for struct sockaddr_in */ #include <stdio.h> #include <playerconfig.h> @@ -64,7 +64,7 @@ typedef void * GEOSGeom; #endif -// Get the message structures from Player +/* Get the message structures from Player*/ #include <libplayercore/playercommon.h> #include <libplayercore/player.h> #include <libplayercore/error.h> @@ -332,10 +332,10 @@ const char *playerc_error_str(void); /** Get the name for a given interface code. */ -//const char *playerc_lookup_name(int code); +/*const char *playerc_lookup_name(int code);*/ /** Get the interface code for a given name. */ -//int playerc_lookup_code(const char *name); +/*int playerc_lookup_code(const char *name);*/ /** Add new entries to the XDR function table. */ int playerc_add_xdr_ftable(playerxdr_function_t *flist, int replace); @@ -344,13 +344,13 @@ /***************************************************************************/ -// Forward declare types +/* Forward declare types*/ struct _playerc_client_t; struct _playerc_device_t; -// forward declaration to avoid including <sys/poll.h>, which may not be -// available when people are building clients against this lib +/* forward declaration to avoid including <sys/poll.h>, which may not be + available when people are building clients against this lib*/ struct pollfd; @@ -365,7 +365,7 @@ @{ */ -// Items in incoming data queue. +/* Items in incoming data queue.*/ typedef struct { player_msghdr_t header; @@ -373,36 +373,36 @@ } playerc_client_item_t; -// Multi-client data +/* Multi-client data*/ typedef struct { - // List of clients being managed + /* List of clients being managed*/ int client_count; struct _playerc_client_t *client[128]; - // Poll info + /* Poll info*/ struct pollfd* pollfd; - // Latest time received from any server + /* Latest time received from any server*/ double time; } playerc_mclient_t; -// Create a multi-client object +/* Create a multi-client object*/ playerc_mclient_t *playerc_mclient_create(void); -// Destroy a multi-client object +/* Destroy a multi-client object*/ void playerc_mclient_destroy(playerc_mclient_t *mclient); -// Add a client to the multi-client (private). +/* Add a client to the multi-client (private).*/ int playerc_mclient_addclient(playerc_mclient_t *mclient, struct _playerc_client_t *client); -// Test to see if there is pending data. -// Returns -1 on error, 0 or 1 otherwise. +/* Test to see if there is pending data. + Returns -1 on error, 0 or 1 otherwise.*/ int playerc_mclient_peek(playerc_mclient_t *mclient, int timeout); -// Read incoming data. The timeout is in ms. Set timeout to a -// negative value to wait indefinitely. +/* Read incoming data. The timeout is in ms. Set timeout to a + negative value to wait indefinitely.*/ int playerc_mclient_read(playerc_mclient_t *mclient, int timeout); /** @} */ @@ -739,11 +739,11 @@ */ void *playerc_client_read(playerc_client_t *client); -// Read and process a packet (nonblocking) -// returns 0 if no data recieved, 1 if data recieved and -1 on error +/* Read and process a packet (nonblocking) + returns 0 if no data recieved, 1 if data recieved and -1 on error*/ int playerc_client_read_nonblock(playerc_client_t *client); -// Read and process a packet (nonblocking), fills in pointer to proxy that got data -// returns 0 if no data recieved, 1 if data recieved and -1 on error +/* Read and process a packet (nonblocking), fills in pointer to proxy that got data + returns 0 if no data recieved, 1 if data recieved and -1 on error*/ int playerc_client_read_nonblock_withproxy(playerc_client_t *client, void ** proxy); /** @brief Set the timeout for client requests. @@ -908,10 +908,10 @@ /** Device info; must be at the start of all device structures. */ playerc_device_t info; - /// The number of valid analog inputs. + /* The number of valid analog inputs.*/ uint8_t voltages_count; - /// A bitfield of the current digital inputs. + /* A bitfield of the current digital inputs.*/ float *voltages; } playerc_aio_t; @@ -1035,7 +1035,7 @@ /** @brief Set the speed of a joint (-1 for all joints) for all subsequent movement commands. */ int playerc_actarray_speed_config(playerc_actarray_t *device, int joint, float speed); -// Set the accelration of a joint (-1 for all joints) for all subsequent movement commands +/* Set the accelration of a joint (-1 for all joints) for all subsequent movement commands*/ int playerc_actarray_accel_config(playerc_actarray_t *device, int joint, float accel); @@ -1440,10 +1440,10 @@ /** Device info; must be at the start of all device structures. */ playerc_device_t info; - /// The number of valid digital inputs. + /*/ The number of valid digital inputs.*/ uint8_t count; - /// A bitfield of the current digital inputs. + /*/ A bitfield of the current digital inputs.*/ uint32_t digin; } playerc_dio_t; @@ -1844,10 +1844,10 @@ /** Device info; must be at the start of all device structures. */ playerc_device_t info; - // data + /* data*/ player_ir_data_t data; - // config + /* config*/ player_ir_pose_t poses; } playerc_ir_t; @@ -1878,7 +1878,47 @@ /***************************************************************************/ +/***************************************************************************/ +/** @ingroup playerc_proxies + * @defgroup playerc_proxy_joystick joystick +The joystick proxy can be used to get images from a joystick. + +@{ +*/ + +/** @brief joystick proxy data. */ +typedef struct +{ + /** Device info; must be at the start of all device structures. */ + playerc_device_t info; + int32_t axes_count; + int32_t pos[8]; + uint32_t buttons; + int * axes_max; + int * axes_min; + double * scale_pos; + + +} playerc_joystick_t; + + +/** @brief Create a joystick proxy. */ +playerc_joystick_t *playerc_joystick_create(playerc_client_t *client, int index); + +/** @brief Destroy a joystick proxy. */ +void playerc_joystick_destroy(playerc_joystick_t *device); + +/** @brief Subscribe to the joystick device. */ +int playerc_joystick_subscribe(playerc_joystick_t *device, int access); + +/** @brief Un-subscribe from the joystick device. */ +int playerc_joystick_unsubscribe(playerc_joystick_t *device); + +/** @} */ +/**************************************************************************/ + + /***************************************************************************/ /** @ingroup playerc_proxies * @defgroup playerc_proxy_laser laser @@ -3299,8 +3339,8 @@ playerc_device_t info; char *rawText; - // Just estimating that no more than 20 words will be spoken between updates. - // Assuming that the longest word is <= 30 characters. + /* Just estimating that no more than 20 words will be spoken between updates. + Assuming that the longest word is <= 30 characters.*/ char **words; int wordCount; } playerc_speechrecognition_t; Modified: code/player/trunk/client_libs/libplayerc++/CMakeLists.txt =================================================================== --- code/player/trunk/client_libs/libplayerc++/CMakeLists.txt 2009-01-11 18:43:03 UTC (rev 7265) +++ code/player/trunk/client_libs/libplayerc++/CMakeLists.txt 2009-01-11 18:48:00 UTC (rev 7266) @@ -173,6 +173,7 @@ healthproxy.cc imuproxy.cc irproxy.cc + joystickproxy.cc laserproxy.cc limbproxy.cc localizeproxy.cc Added: code/player/trunk/client_libs/libplayerc++/joystickproxy.cc =================================================================== --- code/player/trunk/client_libs/libplayerc++/joystickproxy.cc (rev 0) +++ code/player/trunk/client_libs/libplayerc++/joystickproxy.cc 2009-01-11 18:48:00 UTC (rev 7266) @@ -0,0 +1,94 @@ + /* + * Player - One Hell of a Robot Server + * Copyright (C) 2000-2003 + * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + /******************************************************************** + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + ********************************************************************/ + + /* + * $Id: linuxjoystickproxy.cc 4227 2007-10-24 22:32:04Z thjc $ + */ + + #include "playerc++.h" + + using namespace PlayerCc; + + LinuxjoystickProxy::LinuxjoystickProxy(PlayerClient *aPc, uint32_t aIndex) + : ClientProxy(aPc, aIndex), + mDevice(NULL) + { + Subscribe(aIndex); + // how can I get this into the clientproxy.cc? + // right now, we're dependent on knowing its device type + mInfo = &(mDevice->info); + } + + LinuxjoystickProxy::~LinuxjoystickProxy() + { + Unsubscribe(); + } + + void + LinuxjoystickProxy::Subscribe(uint32_t aIndex) + { + scoped_lock_t lock(mPc->mMutex); + mDevice = playerc_joystick_create(mClient, aIndex); + if (NULL==mDevice) + throw PlayerError("LinuxjoystickProxy::LinuxjoystickProxy()", "could not create"); + + if (0 != playerc_joystick_subscribe(mDevice, PLAYER_OPEN_MODE)) + throw PlayerError("LinuxjoystickProxy::LinuxjoystickProxy()", "could not subscribe"); + } + + void + LinuxjoystickProxy::Unsubscribe() + { + assert(NULL!=mDevice); + scoped_lock_t lock(mPc->mMutex); + playerc_joystick_unsubscribe(mDevice); + playerc_joystick_destroy(mDevice); + mDevice = NULL; + } + + std::ostream& + std::operator << (std::ostream &os, const PlayerCc::LinuxjoystickProxy &c) + { + os << "#Linuxjoystick (" << c.GetInterface() << ":" << c.GetIndex() << ")" << std::endl; + for (unsigned int i = 0; i < c.GetAxesCount(); ++i) + os << i << ": " << c[i] << std::endl; + return os; + } + + Modified: code/player/trunk/client_libs/libplayerc++/playerc++.h =================================================================== --- code/player/trunk/client_libs/libplayerc++/playerc++.h 2009-01-11 18:43:03 UTC (rev 7265) +++ code/player/trunk/client_libs/libplayerc++/playerc++.h 2009-01-11 18:48:00 UTC (rev 7266) @@ -1230,7 +1230,56 @@ }; +/** +The @p LinuxjoystickProxy class is used to control a @ref interface_joystick +device. The most recent joystick range measuremts can be read from the +range attribute, or using the the [] operator. +*/ +class LinuxjoystickProxy : public ClientProxy +{ + private: + void Subscribe(uint32_t aIndex); + void Unsubscribe(); + + // libplayerc data structure + playerc_joystick_t *mDevice; + + public: + /// constructor + LinuxjoystickProxy(PlayerClient *aPc, uint32_t aIndex=0); + /// destructor + ~LinuxjoystickProxy(); + + /// return the sensor count + uint32_t GetButtons() const { return GetVar(mDevice->buttons); }; + + /// return a particular scan value + double GetAxes(uint32_t aIndex) const + { if (GetVar(mDevice->axes_count) <= (int32_t)aIndex) return -1.0; return GetVar(mDevice->pos[aIndex]); }; + /// This operator provides an alternate way of access the scan data. + /// For example, LinuxjoystickProxy[0] == LinuxjoystickProxy.GetRange(0) + double operator [] (uint32_t aIndex) const { return GetAxes(aIndex); } + + /// Number of valid joystick poses + uint32_t GetAxesCount() const { return GetVar(mDevice->axes_count); }; + + /// Linuxjoystick poses (m,m,radians) +// player_pose3d_t GetPose(uint32_t aIndex) const +// { return GetVar(mDevice->poses[aIndex]); }; + + // Enable/disable the joysticks. + // Set @p state to 1 to enable, 0 to disable. + // Note that when joysticks are disabled the client will still receive joystick + // data, but the ranges will always be the last value read from the joysticks + // before they were disabled. + //void SetEnable(bool aEnable); + + /// Request the joystick geometry. +// void RequestGeom(); +}; + + /** The @p LocalizeProxy class is used to control a @ref interface_localize device, which can provide multiple pose @@ -2563,6 +2612,7 @@ std::ostream& operator << (std::ostream& os, const PlayerCc::IrProxy& c); std::ostream& operator << (std::ostream& os, const PlayerCc::LaserProxy& c); std::ostream& operator << (std::ostream& os, const PlayerCc::LimbProxy& c); + std::ostream& operator << (std::ostream& os, const PlayerCc::LinuxjoystickProxy& c); std::ostream& operator << (std::ostream& os, const PlayerCc::LocalizeProxy& c); std::ostream& operator << (std::ostream& os, const PlayerCc::LogProxy& c); std::ostream& operator << (std::ostream& os, const PlayerCc::MapProxy& c); Modified: code/player/trunk/libplayercore/interfaces/049_joystick.def =================================================================== --- code/player/trunk/libplayercore/interfaces/049_joystick.def 2009-01-11 18:43:03 UTC (rev 7265) +++ code/player/trunk/libplayercore/interfaces/049_joystick.def 2009-01-11 18:48:00 UTC (rev 7266) @@ -13,14 +13,17 @@ /** @brief Data: state (@ref PLAYER_JOYSTICK_DATA_STATE) The joystick data packet, which contains the current state of the -joystick */ -typedef struct player_joystick_data -{ + joystick */ + typedef struct player_joystick_data + { /** Current joystick position X, Y and Yaw (unscaled) */ - int32_t pos[3]; - /** Scaling factors for X, Y and Yaw */ - int32_t scale[3]; - /** Button states (bitmask) */ - uint32_t buttons; -} player_joystick_data_t; + int32_t pos[8]; + /** Scaling factors for X, Y and Yaw --- not using these yet*/ + int32_t scale[8]; + /** Button states (bitmask) */ + uint32_t buttons; + /** Nunber of axes */ + uint32_t axes_count; + } player_joystick_data_t; + Modified: code/player/trunk/server/drivers/joystick/linuxjoy.cc =================================================================== --- code/player/trunk/server/drivers/joystick/linuxjoy.cc 2009-01-11 18:43:03 UTC (rev 7265) +++ code/player/trunk/server/drivers/joystick/linuxjoy.cc 2009-01-11 18:48:00 UTC (rev 7266) @@ -229,6 +229,7 @@ #define XAXIS 1 #define YAXIS 2 #define YAWAXIS 0 +#define SLIDER 3 #define MAX_XSPEED 0.5 #define MAX_YSPEED 0.5 @@ -276,11 +277,12 @@ private: player_devaddr_t joystick_addr; private: const char *dev; private: int fd; - private: int16_t pos[3]; - private: uint16_t buttons; - private: int axes_max[3]; - private: int axes_min[3]; - private: double scale_pos[3]; + private: int axes_count; + private: int32_t pos[4]; + private: uint32_t buttons; + private: int axes_max[4]; + private: int axes_min[4]; + private: double scale_pos[4]; private: double timeout; private: struct timeval lastread; @@ -289,8 +291,8 @@ private: player_position2d_data_t pos_data; // These are used when we send commands to a position device - private: double max_speed[3]; - private: int axes[3]; + private: double max_speed[4]; + private: int axes[4]; private: int deadman_button; private: player_devaddr_t cmd_position_addr; private: Device * position; @@ -360,9 +362,14 @@ } this->dev = cf->ReadString(section, "port", "/dev/js0"); +// partially implementing axes_count + this->axes_count=4; this->axes[0] = cf->ReadTupleInt(section,"axes", 0, XAXIS); this->axes[1] = cf->ReadTupleInt(section,"axes", 1, YAXIS); this->axes[2] = cf->ReadTupleInt(section,"axes", 2, YAWAXIS); + this->axes[3] = cf->ReadTupleInt(section,"axes", 3, SLIDER); + + this->deadman_button = cf->ReadInt(section,"deadman", -1); this->axes_max[0] = cf->ReadTupleInt(section, "axes_maxima", 0, XAXIS_MAX); this->axes_max[1] = cf->ReadTupleInt(section, "axes_maxima", 1, YAXIS_MAX); @@ -445,7 +452,7 @@ } } - this->pos[0] = this->pos[1] = this->pos[2] = 0; + this->pos[0] = this->pos[1] = this->pos[2] = this->pos[3] = 0; return 0; } @@ -571,6 +578,7 @@ fd.events = POLLIN | POLLHUP; fd.revents = 0; + count = poll(&fd, 1, 10); if (count < 0) PLAYER_ERROR1("poll returned error [%s]", strerror(errno)); @@ -590,10 +598,12 @@ // Update buttons if ((event.type & ~JS_EVENT_INIT) == JS_EVENT_BUTTON) { + if (event.value) this->buttons |= (1 << event.number); else this->buttons &= ~(1 << event.number); + } // ignore the startup events @@ -625,6 +635,13 @@ this->pos[2] = 0; GlobalTime->GetTime(&this->lastread); } + else if(event.number == this->axes[3]) + { + this->pos[3] = event.value; + if(abs(this->pos[3]) < this->axes_min[3]) + this->pos[3] = 0; + GlobalTime->GetTime(&this->lastread); + } } break; } @@ -638,16 +655,22 @@ // Send new data out void LinuxJoystick::RefreshData() { + int i; if(this->joystick_addr.interf) { memset(&(this->joy_data),0,sizeof(player_joystick_data_t)); - this->joy_data.pos[0] = this->pos[0]; - this->joy_data.pos[1] = this->pos[1]; - this->joy_data.pos[2] = this->pos[2]; + + this->joy_data.buttons = this->buttons; + this->joy_data.axes_count = this->axes_count; + for (i = 0; i < joy_data.axes_count ; i++) + this->joy_data.pos[i] = this->pos[i]; + + this->joy_data.scale[0] = this->axes_max[0]; this->joy_data.scale[1] = this->axes_max[1]; this->joy_data.scale[2] = this->axes_max[2]; - this->joy_data.buttons = this->buttons; + this->joy_data.scale[3] = this->axes_max[3]; + this->Publish(this->joystick_addr, PLAYER_MSGTYPE_DATA, PLAYER_JOYSTICK_DATA_STATE, (void*)&this->joy_data, sizeof(this->joy_data), NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |