24 #include <interfaces/RobotinoSensorInterface.h> 26 #include <core/exceptions/software.h> 44 RobotinoSensorInterface::RobotinoSensorInterface() : Interface()
46 data_size =
sizeof(RobotinoSensorInterface_data_t);
47 data_ptr = malloc(data_size);
48 data = (RobotinoSensorInterface_data_t *)data_ptr;
49 data_ts = (interface_data_ts_t *)data_ptr;
50 memset(data_ptr, 0, data_size);
51 add_fieldinfo(IFT_FLOAT,
"mot_velocity", 3, &data->mot_velocity);
52 add_fieldinfo(IFT_INT32,
"mot_position", 3, &data->mot_position);
53 add_fieldinfo(IFT_FLOAT,
"mot_current", 3, &data->mot_current);
54 add_fieldinfo(IFT_BOOL,
"bumper", 1, &data->bumper);
55 add_fieldinfo(IFT_FLOAT,
"distance", 9, &data->distance);
56 add_fieldinfo(IFT_BOOL,
"digital_in", 8, &data->digital_in);
57 add_fieldinfo(IFT_BOOL,
"digital_out", 8, &data->digital_out);
58 add_fieldinfo(IFT_FLOAT,
"analog_in", 8, &data->analog_in);
59 add_fieldinfo(IFT_BOOL,
"bumper_estop_enabled", 1, &data->bumper_estop_enabled);
60 add_messageinfo(
"SetBumperEStopEnabledMessage");
61 add_messageinfo(
"SetDigitalOutputMessage");
62 unsigned char tmp_hash[] = {0xa5, 0xb, 0xa1, 0x94, 0xea, 0x39, 0x14, 0x7, 0x98, 0x77, 0x10, 0xc, 0x25, 0x72, 0x57, 0xa0};
67 RobotinoSensorInterface::~RobotinoSensorInterface()
77 RobotinoSensorInterface::mot_velocity()
const 79 return data->mot_velocity;
89 RobotinoSensorInterface::mot_velocity(
unsigned int index)
const 92 throw Exception(
"Index value %u out of bounds (0..3)", index);
94 return data->mot_velocity[index];
102 RobotinoSensorInterface::maxlenof_mot_velocity()
const 112 RobotinoSensorInterface::set_mot_velocity(
const float * new_mot_velocity)
114 memcpy(data->mot_velocity, new_mot_velocity,
sizeof(
float) * 3);
124 RobotinoSensorInterface::set_mot_velocity(
unsigned int index,
const float new_mot_velocity)
127 throw Exception(
"Index value %u out of bounds (0..3)", index);
129 data->mot_velocity[index] = new_mot_velocity;
137 RobotinoSensorInterface::mot_position()
const 139 return data->mot_position;
149 RobotinoSensorInterface::mot_position(
unsigned int index)
const 152 throw Exception(
"Index value %u out of bounds (0..3)", index);
154 return data->mot_position[index];
162 RobotinoSensorInterface::maxlenof_mot_position()
const 172 RobotinoSensorInterface::set_mot_position(
const int32_t * new_mot_position)
174 memcpy(data->mot_position, new_mot_position,
sizeof(int32_t) * 3);
184 RobotinoSensorInterface::set_mot_position(
unsigned int index,
const int32_t new_mot_position)
187 throw Exception(
"Index value %u out of bounds (0..3)", index);
189 data->mot_position[index] = new_mot_position;
197 RobotinoSensorInterface::mot_current()
const 199 return data->mot_current;
209 RobotinoSensorInterface::mot_current(
unsigned int index)
const 212 throw Exception(
"Index value %u out of bounds (0..3)", index);
214 return data->mot_current[index];
222 RobotinoSensorInterface::maxlenof_mot_current()
const 232 RobotinoSensorInterface::set_mot_current(
const float * new_mot_current)
234 memcpy(data->mot_current, new_mot_current,
sizeof(
float) * 3);
244 RobotinoSensorInterface::set_mot_current(
unsigned int index,
const float new_mot_current)
247 throw Exception(
"Index value %u out of bounds (0..3)", index);
249 data->mot_current[index] = new_mot_current;
257 RobotinoSensorInterface::is_bumper()
const 267 RobotinoSensorInterface::maxlenof_bumper()
const 277 RobotinoSensorInterface::set_bumper(
const bool new_bumper)
279 data->bumper = new_bumper;
288 RobotinoSensorInterface::distance()
const 290 return data->distance;
300 RobotinoSensorInterface::distance(
unsigned int index)
const 303 throw Exception(
"Index value %u out of bounds (0..9)", index);
305 return data->distance[index];
313 RobotinoSensorInterface::maxlenof_distance()
const 323 RobotinoSensorInterface::set_distance(
const float * new_distance)
325 memcpy(data->distance, new_distance,
sizeof(
float) * 9);
335 RobotinoSensorInterface::set_distance(
unsigned int index,
const float new_distance)
338 throw Exception(
"Index value %u out of bounds (0..9)", index);
340 data->distance[index] = new_distance;
348 RobotinoSensorInterface::is_digital_in()
const 350 return data->digital_in;
360 RobotinoSensorInterface::is_digital_in(
unsigned int index)
const 363 throw Exception(
"Index value %u out of bounds (0..8)", index);
365 return data->digital_in[index];
373 RobotinoSensorInterface::maxlenof_digital_in()
const 383 RobotinoSensorInterface::set_digital_in(
const bool * new_digital_in)
385 memcpy(data->digital_in, new_digital_in,
sizeof(
bool) * 8);
395 RobotinoSensorInterface::set_digital_in(
unsigned int index,
const bool new_digital_in)
398 throw Exception(
"Index value %u out of bounds (0..8)", index);
400 data->digital_in[index] = new_digital_in;
408 RobotinoSensorInterface::is_digital_out()
const 410 return data->digital_out;
420 RobotinoSensorInterface::is_digital_out(
unsigned int index)
const 423 throw Exception(
"Index value %u out of bounds (0..8)", index);
425 return data->digital_out[index];
433 RobotinoSensorInterface::maxlenof_digital_out()
const 443 RobotinoSensorInterface::set_digital_out(
const bool * new_digital_out)
445 memcpy(data->digital_out, new_digital_out,
sizeof(
bool) * 8);
455 RobotinoSensorInterface::set_digital_out(
unsigned int index,
const bool new_digital_out)
458 throw Exception(
"Index value %u out of bounds (0..8)", index);
460 data->digital_out[index] = new_digital_out;
468 RobotinoSensorInterface::analog_in()
const 470 return data->analog_in;
480 RobotinoSensorInterface::analog_in(
unsigned int index)
const 483 throw Exception(
"Index value %u out of bounds (0..8)", index);
485 return data->analog_in[index];
493 RobotinoSensorInterface::maxlenof_analog_in()
const 503 RobotinoSensorInterface::set_analog_in(
const float * new_analog_in)
505 memcpy(data->analog_in, new_analog_in,
sizeof(
float) * 8);
515 RobotinoSensorInterface::set_analog_in(
unsigned int index,
const float new_analog_in)
518 throw Exception(
"Index value %u out of bounds (0..8)", index);
520 data->analog_in[index] = new_analog_in;
530 RobotinoSensorInterface::is_bumper_estop_enabled()
const 532 return data->bumper_estop_enabled;
540 RobotinoSensorInterface::maxlenof_bumper_estop_enabled()
const 552 RobotinoSensorInterface::set_bumper_estop_enabled(
const bool new_bumper_estop_enabled)
554 data->bumper_estop_enabled = new_bumper_estop_enabled;
560 RobotinoSensorInterface::create_message(
const char *type)
const 562 if ( strncmp(
"SetBumperEStopEnabledMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
564 }
else if ( strncmp(
"SetDigitalOutputMessage", type, __INTERFACE_MESSAGE_TYPE_SIZE) == 0 ) {
568 "message type for this interface type.", type);
577 RobotinoSensorInterface::copy_values(
const Interface *other)
582 type(), other->
type());
584 memcpy(data, oi->data,
sizeof(RobotinoSensorInterface_data_t));
588 RobotinoSensorInterface::enum_tostring(
const char *enumtype,
int val)
const 604 RobotinoSensorInterface::SetBumperEStopEnabledMessage::SetBumperEStopEnabledMessage(
const bool ini_enabled) :
Message(
"SetBumperEStopEnabledMessage")
606 data_size =
sizeof(SetBumperEStopEnabledMessage_data_t);
609 data = (SetBumperEStopEnabledMessage_data_t *)
data_ptr;
611 data->enabled = ini_enabled;
617 data_size =
sizeof(SetBumperEStopEnabledMessage_data_t);
620 data = (SetBumperEStopEnabledMessage_data_t *)
data_ptr;
639 data = (SetBumperEStopEnabledMessage_data_t *)
data_ptr;
654 return data->enabled;
677 data->enabled = new_enabled;
703 data_size =
sizeof(SetDigitalOutputMessage_data_t);
706 data = (SetDigitalOutputMessage_data_t *)
data_ptr;
708 data->digital_out = ini_digital_out;
709 data->enabled = ini_enabled;
716 data_size =
sizeof(SetDigitalOutputMessage_data_t);
719 data = (SetDigitalOutputMessage_data_t *)
data_ptr;
739 data = (SetDigitalOutputMessage_data_t *)
data_ptr;
753 return data->digital_out;
775 data->digital_out = new_digital_out;
787 return data->enabled;
809 data->enabled = new_enabled;
bool is_enabled() const
Get enabled value.
void * data_ptr
Pointer to memory that contains local data.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Fawkes library namespace.
SetDigitalOutputMessage()
Constructor.
8 bit unsigned integer field
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
bool is_enabled() const
Get enabled value.
Base class for all Fawkes BlackBoard interfaces.
void set_enabled(const bool new_enabled)
Set enabled value.
virtual bool message_valid(const Message *message) const
Check if message is valid and can be enqueued.
virtual Message * clone() const
Clone this message.
message_data_ts_t * data_ts
data timestamp aliasing pointer
unsigned int data_size
Size of memory needed to hold all data.
RobotinoSensorInterface Fawkes BlackBoard Interface.
~SetDigitalOutputMessage()
Destructor.
size_t maxlenof_enabled() const
Get maximum length of enabled value.
void set_enabled(const bool new_enabled)
Set enabled value.
const char * type() const
Get type of interface.
Base class for exceptions in Fawkes.
virtual Message * clone() const
Clone this message.
SetBumperEStopEnabledMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_digital_out() const
Get maximum length of digital_out value.
SetBumperEStopEnabledMessage()
Constructor.
void set_digital_out(const uint8_t new_digital_out)
Set digital_out value.
SetDigitalOutputMessage Fawkes BlackBoard Interface Message.
~SetBumperEStopEnabledMessage()
Destructor.
uint8_t digital_out() const
Get digital_out value.
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.
size_t maxlenof_enabled() const
Get maximum length of enabled value.