p_gripper.cc
Go to the documentation of this file.
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2004, 2005 Richard Vaughan
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 /*
23  * Desc: A plugin driver for Player that gives access to Stage devices.
24  * Author: Richard Vaughan
25  * Date: 10 December 2004
26  * CVS: $Id$
27  */
28 
29 
30 #include "p_driver.h"
31 
32 //#include "playerclient.h" // for the dumb pioneer gripper command defines
33 
41 #include "p_driver.h"
42 using namespace Stg;
43 
44 InterfaceGripper::InterfaceGripper( player_devaddr_t addr,
45  StgDriver* driver,
46  ConfigFile* cf,
47  int section )
48  : InterfaceModel( addr, driver, cf, section, "gripper" )
49 {
50  // nothing to do
51 }
52 
54 {
55  ModelGripper * gmod = reinterpret_cast<ModelGripper*> (this->mod);
56 
57  player_gripper_data_t pdata;
58  memset( &pdata, 0, sizeof(pdata) );
59 
60  // set the proper bits
61  pdata.beams = 0;
62  pdata.beams |= gmod->GetConfig().beam[0] ? 0x04 : 0x00;
63  pdata.beams |= gmod->GetConfig().beam[1] ? 0x08 : 0x00;
64 
65  switch (gmod->GetConfig().paddles)
66  {
67  case ModelGripper::PADDLE_OPEN:
68  pdata.state = PLAYER_GRIPPER_STATE_OPEN;
69  break;
70  case ModelGripper::PADDLE_CLOSED:
71  pdata.state = PLAYER_GRIPPER_STATE_CLOSED;
72  break;
73  case ModelGripper::PADDLE_OPENING:
74  case ModelGripper::PADDLE_CLOSING:
75  pdata.state = PLAYER_GRIPPER_STATE_MOVING;
76  break;
77  default:
78  pdata.state = PLAYER_GRIPPER_STATE_ERROR;
79  }
80 
81  // Write data
82  this->driver->Publish(this->addr,
83  PLAYER_MSGTYPE_DATA,
84  PLAYER_GRIPPER_DATA_STATE,
85  (void*)&pdata);
86 
87 }
88 
89 int InterfaceGripper::ProcessMessage(QueuePointer& resp_queue,
90  player_msghdr_t* hdr,
91  void* data)
92 {
93  ModelGripper * gmod = reinterpret_cast<ModelGripper*> (this->mod);
94 
95  if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD, PLAYER_GRIPPER_CMD_OPEN, this->addr))
96  {
97  gmod->CommandOpen();
98  return 0;
99  }
100  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD, PLAYER_GRIPPER_CMD_CLOSE, this->addr))
101  {
102  gmod->CommandClose();
103  return 0;
104  }
105 
106  if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ, PLAYER_GRIPPER_REQ_GET_GEOM, this->addr))
107  {
108  Geom geom = this->mod->GetGeom();
109  Pose pose = this->mod->GetPose();
110 
111  player_gripper_geom_t pgeom;
112  memset(&pgeom, 0, sizeof(pgeom));
113 
114  pgeom.pose.px = pose.x;
115  pgeom.pose.py = pose.y;
116  pgeom.pose.pz = pose.z;
117  pgeom.pose.pyaw = pose.a;
118 
119  pgeom.outer_size.sl = geom.size.x;
120  pgeom.outer_size.sw = geom.size.y;
121  pgeom.outer_size.sh = geom.size.z;
122 
123  pgeom.num_beams = 2;
124 
125  this->driver->Publish(this->addr, resp_queue, PLAYER_MSGTYPE_RESP_ACK, PLAYER_GRIPPER_REQ_GET_GEOM, (void*)&pgeom);
126  return(0);
127  }
128 
129  PRINT_WARN2( "stage gripper doesn't support message id:%d/%d", hdr->type, hdr->subtype );
130  return -1;
131 }
132 
void CommandOpen()
Definition: stage.hh:2661
The Stage library uses its own namespace.
Definition: canvas.hh:8
void CommandClose()
Definition: stage.hh:2659
meters_t x
Definition: stage.hh:228
#define PRINT_WARN2(m, a, b)
Definition: stage.hh:635
Size size
extent
Definition: stage.hh:395
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr_t *hdr, void *data)
Definition: p_gripper.cc:89
StgDriver * driver
Definition: p_driver.h:72
meters_t z
location in 3 axes
Definition: stage.hh:251
meters_t y
Definition: stage.hh:251
player_devaddr_t addr
Definition: p_driver.h:66
Model * beam[2]
points to a model detected by the beams
Definition: stage.hh:2616
meters_t y
Definition: stage.hh:228
meters_t z
Definition: stage.hh:228
Stg::Model * mod
Definition: p_driver.h:115
virtual void Publish(void)
Definition: p_gripper.cc:53
paddle_state_t paddles
Definition: stage.hh:2607
Pose GetPose() const
Definition: stage.hh:2382
radians_t a
rotation about the z axis.
Definition: stage.hh:252
config_t GetConfig()
Definition: stage.hh:2654
meters_t x
Definition: stage.hh:251
InterfaceGripper(player_devaddr_t addr, StgDriver *driver, ConfigFile *cf, int section)
Definition: p_gripper.cc:44
Geom GetGeom() const
Definition: stage.hh:2378


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09