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
data->position = new_position;
97
data_changed
=
true
;
98
}
99
100
/** Get velocity value.
101
*
102
The joint's velocity in rad/s.
103
104
* @return velocity value
105
*/
106
float
107
JointInterface::velocity
()
const
108
{
109
return
data->velocity;
110
}
111
112
/** Get maximum length of velocity value.
113
* @return length of velocity value, can be length of the array or number of
114
* maximum number of characters for a string
115
*/
116
size_t
117
JointInterface::maxlenof_velocity
()
const
118
{
119
return
1;
120
}
121
122
/** Set velocity value.
123
*
124
The joint's velocity in rad/s.
125
126
* @param new_velocity new velocity value
127
*/
128
void
129
JointInterface::set_velocity
(
const
float
new_velocity)
130
{
131
data->velocity = new_velocity;
132
data_changed
=
true
;
133
}
134
135
/* =========== message create =========== */
136
Message
*
137
JointInterface::create_message
(
const
char
*
type
)
const
138
{
139
throw
UnknownTypeException
(
"The given type '%s' does not match any known "
140
"message type for this interface type."
,
type
);
141
}
142
143
144
/** Copy values from other interface.
145
* @param other other interface to copy values from
146
*/
147
void
148
JointInterface::copy_values
(
const
Interface
*other)
149
{
150
const
JointInterface
*oi =
dynamic_cast<
const
JointInterface
*
>
(other);
151
if
(oi == NULL) {
152
throw
TypeMismatchException
(
"Can only copy values from interface of same type (%s vs. %s)"
,
153
type
(), other->
type
());
154
}
155
memcpy(data, oi->data,
sizeof
(JointInterface_data_t));
156
}
157
158
const
char
*
159
JointInterface::enum_tostring
(
const
char
*enumtype,
int
val)
const
160
{
161
throw
UnknownTypeException(
"Unknown enum type %s"
, enumtype);
162
}
163
164
/* =========== messages =========== */
165
/** Check if message is valid and can be enqueued.
166
* @param message Message to check
167
* @return true if the message is valid, false otherwise.
168
*/
169
bool
170
JointInterface::message_valid
(
const
Message
*message)
const
171
{
172
return
false
;
173
}
174
175
/// @cond INTERNALS
176
EXPORT_INTERFACE(
JointInterface
)
177
/// @endcond
178
179
180
}
// end namespace fawkes
fawkes::Interface::data_ptr
void * data_ptr
Definition:
interface.h:224
fawkes::JointInterface::maxlenof_velocity
size_t maxlenof_velocity() const
Get maximum length of velocity value.
Definition:
JointInterface.cpp:123
fawkes::Message
Definition:
message.h:41
fawkes::Message::data_ptr
void * data_ptr
Definition:
message.h:125
fawkes::JointInterface::message_valid
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
Definition:
JointInterface.cpp:176
fawkes::JointInterface::set_position
void set_position(const float new_position)
Set position value.
Definition:
JointInterface.cpp:100
fawkes::JointInterface::copy_values
virtual void copy_values(const Interface *other)
Copy values from other interface.
Definition:
JointInterface.cpp:154
fawkes::IFT_FLOAT
@ IFT_FLOAT
float field
Definition:
types.h:60
fawkes::Message::data_ts
message_data_ts_t * data_ts
data timestamp aliasing pointer
Definition:
message.h:135
fawkes::Interface::type
const char * type() const
Get type of interface.
Definition:
interface.cpp:645
fawkes::JointInterface::set_velocity
void set_velocity(const float new_velocity)
Set velocity value.
Definition:
JointInterface.cpp:135
fawkes::JointInterface::velocity
float velocity() const
Get velocity value.
Definition:
JointInterface.cpp:113
fawkes::TypeMismatchException
Definition:
software.h:49
fawkes::Interface::data_changed
bool data_changed
Definition:
interface.h:226
fawkes::UnknownTypeException
Definition:
software.h:55
fawkes
fawkes::Interface::set_hash
void set_hash(unsigned char *ihash)
Set hash.
Definition:
interface.cpp:321
fawkes::Message::data_size
unsigned int data_size
Definition:
message.h:126
fawkes::Interface
Definition:
interface.h:78
fawkes::JointInterface::create_message
virtual Message * create_message(const char *type) const
Definition:
JointInterface.cpp:143
fawkes::JointInterface
Definition:
JointInterface.h:39
fawkes::JointInterface::enum_tostring
virtual const char * enum_tostring(const char *enumtype, int val) const
Definition:
JointInterface.cpp:165
fawkes::Message::add_fieldinfo
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
Definition:
message.cpp:406
fawkes::JointInterface::position
float position() const
Get position value.
Definition:
JointInterface.cpp:78
fawkes::JointInterface::maxlenof_position
size_t maxlenof_position() const
Get maximum length of position value.
Definition:
JointInterface.cpp:88
src
libs
interfaces
JointInterface.cpp
Generated by
1.8.17