p_actarray.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 // DOCUMENTATION ------------------------------------------------------------
29 
38 // CODE ----------------------------------------------------------------------
39 
40 #include "p_driver.h"
41 //#include "playerclient.h"
42 
43 
44 InterfaceActArray::InterfaceActArray( player_devaddr_t addr,
45  StgDriver* driver,
46  ConfigFile* cf,
47  int section )
48 
49  : InterfaceModel( addr, driver, cf, section, "actuator" )
50 {
51  //puts( "InterfacePosition constructor" );
52 }
53 
54 int InterfaceActArray::ProcessMessage(QueuePointer &resp_queue,
55  player_msghdr_t* hdr,
56  void* data)
57 {
58  Stg::ModelActuator* actmod = (Stg::ModelActuator*)this->mod;
59 
60  // Is it a new motor command?
61  if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ,
62  PLAYER_ACTARRAY_REQ_GET_GEOM,
63  this->addr))
64  {
65  Stg::Geom geom = actmod->GetGeom();
66 
67  // fill in the geometry data formatted player-like
68  // TODO actually get real data here
69  player_actarray_actuatorgeom_t actuator = {0};
70  actuator.min = actmod->GetMinPosition();
71  actuator.max = actmod->GetMaxPosition();
72  actuator.type = PLAYER_ACTARRAY_TYPE_LINEAR;
73 
74  player_actarray_geom_t pgeom = {0};
75  pgeom.base_pos.px = geom.pose.x;
76  pgeom.base_pos.py = geom.pose.y;
77  pgeom.base_pos.pz = geom.pose.z;
78 
79  pgeom.base_orientation.pyaw = geom.pose.a;
80 
81  pgeom.actuators_count = 1;
82  pgeom.actuators = &actuator;
83 
84  this->driver->Publish( this->addr, resp_queue,
85  PLAYER_MSGTYPE_RESP_ACK,
86  PLAYER_ACTARRAY_REQ_GET_GEOM,
87  (void*)&pgeom);
88  return 0;
89  }
90  // Is it a request to reset odometry?
91  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
92  PLAYER_ACTARRAY_CMD_POS,
93  this->addr))
94  {
95  player_actarray_position_cmd_t &cmd = *reinterpret_cast<player_actarray_position_cmd_t*> (data);
96  actmod->GoTo(cmd.position);
97  return 0;
98  }
99  // Is it a request to reset odometry?
100  else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_CMD,
101  PLAYER_ACTARRAY_CMD_SPEED,
102  this->addr))
103  {
104  player_actarray_speed_cmd_t &cmd = *reinterpret_cast<player_actarray_speed_cmd_t*> (data);
105  actmod->SetSpeed(cmd.speed);
106  return 0;
107  }
108  //else
109 
110  // Don't know how to handle this message.
111  PRINT_WARN2( "actuator doesn't support msg with type %d subtype %d",
112  hdr->type, hdr->subtype);
113  return(-1);
114 }
115 
117 {
118  Stg::ModelActuator* actmod = (Stg::ModelActuator*)this->mod;
119 
120  // TODO fill in values here
121  player_actarray_actuator_t act = {0};
122  act.position = actmod->GetPosition();
123  act.speed = actmod->GetSpeed();
124  if (act.speed != 0)
125  act.state = PLAYER_ACTARRAY_ACTSTATE_MOVING;
126  else
127  act.state = PLAYER_ACTARRAY_ACTSTATE_IDLE;
128 
129  player_actarray_data_t actdata = {0};
130  actdata.actuators_count = 1;
131  actdata.actuators = &act;
132 
133 
134  // publish this data
135  this->driver->Publish( this->addr,
136  PLAYER_MSGTYPE_DATA, PLAYER_ACTARRAY_DATA_STATE,
137  (void*)&actdata);
138 }
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Definition: p_actarray.cc:54
#define PRINT_WARN2(m, a, b)
Definition: stage.hh:635
double GetSpeed() const
Definition: stage.hh:3099
void GoTo(double pose)
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
void SetSpeed(double speed)
double GetMinPosition() const
Definition: stage.hh:3107
Pose pose
position
Definition: stage.hh:394
double GetMaxPosition() const
Definition: stage.hh:3106
Stg::Model * mod
Definition: p_driver.h:115
InterfaceActArray(player_devaddr_t addr, StgDriver *driver, ConfigFile *cf, int section)
Definition: p_actarray.cc:44
ModelActuator class
Definition: stage.hh:3053
radians_t a
rotation about the z axis.
Definition: stage.hh:252
virtual void Publish(void)
Definition: p_actarray.cc:116
meters_t x
Definition: stage.hh:251
double GetPosition() const
Definition: stage.hh:3105
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