Fawkes API  Fawkes Development Version
JointInterface.cpp
1 
2 /***************************************************************************
3  * JointInterface.cpp - Fawkes BlackBoard Interface - JointInterface
4  *
5  * Templated created: Thu Oct 12 10:49:19 2006
6  * Copyright 2013 Till Hofmann
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <interfaces/JointInterface.h>
25 
26 #include <core/exceptions/software.h>
27 
28 #include <map>
29 #include <string>
30 #include <cstring>
31 #include <cstdlib>
32 
33 namespace fawkes {
34 
35 /** @class JointInterface <interfaces/JointInterface.h>
36  * JointInterface Fawkes BlackBoard Interface.
37  *
38  Storage for a single joint state.
39 
40  * @ingroup FawkesInterfaces
41  */
42 
43 
44 
45 /** Constructor */
46 JointInterface::JointInterface() : Interface()
47 {
48  data_size = sizeof(JointInterface_data_t);
49  data_ptr = malloc(data_size);
50  data = (JointInterface_data_t *)data_ptr;
51  data_ts = (interface_data_ts_t *)data_ptr;
52  memset(data_ptr, 0, data_size);
53  add_fieldinfo(IFT_FLOAT, "position", 1, &data->position);
54  add_fieldinfo(IFT_FLOAT, "velocity", 1, &data->velocity);
55  unsigned char tmp_hash[] = {0xd2, 0x74, 0x1b, 0x6a, 0x5b, 0xf, 0xa9, 0xe1, 0xb0, 0xa8, 0x47, 0x84, 0x6f, 0x8f, 0x1c, 0xab};
56  set_hash(tmp_hash);
57 }
58 
59 /** Destructor */
60 JointInterface::~JointInterface()
61 {
62  free(data_ptr);
63 }
64 /* Methods */
65 /** Get position value.
66  *
67  The joint's position in rad.
68 
69  * @return position value
70  */
71 float
72 JointInterface::position() const
73 {
74  return data->position;
75 }
76 
77 /** Get maximum length of position value.
78  * @return length of position value, can be length of the array or number of
79  * maximum number of characters for a string
80  */
81 size_t
82 JointInterface::maxlenof_position() const
83 {
84  return 1;
85 }
86 
87 /** Set position value.
88  *
89  The joint's position in rad.
90 
91  * @param new_position new position value
92  */
93 void
94 JointInterface::set_position(const float new_position)
95 {
96  set_field(data->position, new_position);
97 }
98 
99 /** Get velocity value.
100  *
101  The joint's velocity in rad/s.
102 
103  * @return velocity value
104  */
105 float
106 JointInterface::velocity() const
107 {
108  return data->velocity;
109 }
110 
111 /** Get maximum length of velocity value.
112  * @return length of velocity value, can be length of the array or number of
113  * maximum number of characters for a string
114  */
115 size_t
116 JointInterface::maxlenof_velocity() const
117 {
118  return 1;
119 }
120 
121 /** Set velocity value.
122  *
123  The joint's velocity in rad/s.
124 
125  * @param new_velocity new velocity value
126  */
127 void
128 JointInterface::set_velocity(const float new_velocity)
129 {
130  set_field(data->velocity, new_velocity);
131 }
132 
133 /* =========== message create =========== */
134 Message *
135 JointInterface::create_message(const char *type) const
136 {
137  throw UnknownTypeException("The given type '%s' does not match any known "
138  "message type for this interface type.", type);
139 }
140 
141 
142 /** Copy values from other interface.
143  * @param other other interface to copy values from
144  */
145 void
146 JointInterface::copy_values(const Interface *other)
147 {
148  const JointInterface *oi = dynamic_cast<const JointInterface *>(other);
149  if (oi == NULL) {
150  throw TypeMismatchException("Can only copy values from interface of same type (%s vs. %s)",
151  type(), other->type());
152  }
153  memcpy(data, oi->data, sizeof(JointInterface_data_t));
154 }
155 
156 const char *
157 JointInterface::enum_tostring(const char *enumtype, int val) const
158 {
159  throw UnknownTypeException("Unknown enum type %s", enumtype);
160 }
161 
162 /* =========== messages =========== */
163 /** Check if message is valid and can be enqueued.
164  * @param message Message to check
165  * @return true if the message is valid, false otherwise.
166  */
167 bool
168 JointInterface::message_valid(const Message *message) const
169 {
170  return false;
171 }
172 
173 /// @cond INTERNALS
174 EXPORT_INTERFACE(JointInterface)
175 /// @endcond
176 
177 
178 } // end namespace fawkes
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
const char * type() const
Get type of interface.
Definition: interface.cpp:652
JointInterface Fawkes BlackBoard Interface.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Fawkes library namespace.