27 #include <sys/types.h> 50 px += ((this->
xpos / 1e3) *
cos(rot) -
52 py += ((this->
xpos / 1e3) *
sin(rot) +
56 px += this->
xpos / 1e3;
57 py += this->
ypos / 1e3;
65 data->
position.pose.pose.position.x = px;
66 data->
position.pose.pose.position.y = py;
67 data->
position.pose.pose.position.z = 0.0;
72 data->
position.twist.twist.linear.y = 0.0;
73 data->
position.twist.twist.angular.z =
78 1e-3, 0, 0, 0, 0, 0, 0, 1e-3, 0, 0, 0, 0, 0, 0, 1e6, 0, 0, 0, 0, 0, 0, 1e6, 0, 0, 0, 0, 0, 0,
79 1e6, 0, 0, 0, 0, 0, 0, 1e3
83 1e-3, 0, 0, 0, 0, 0, 0, 1e-3, 0, 0, 0, 0, 0, 0, 1e6, 0, 0, 0, 0, 0, 0, 1e6, 0, 0, 0, 0, 0, 0,
84 1e6, 0, 0, 0, 0, 0, 0, 1e3
114 data->
sonar.ranges.clear();
115 for (
int i = 0; i < data->
sonar.ranges_count; i++) {
121 unsigned char gripState =
timer;
122 if ((gripState & 0x01) && (gripState & 0x02) && !(gripState & 0x04)) {
125 }
else if (gripState & 0x04) {
127 if (gripState & 0x01) {
130 if (gripState & 0x02) {
133 }
else if (gripState & 0x01) {
136 }
else if (gripState & 0x02) {
142 data->
gripper.grip.inner_beam =
false;
143 data->
gripper.grip.outer_beam =
false;
144 data->
gripper.grip.left_contact =
false;
145 data->
gripper.grip.right_contact =
false;
148 data->
gripper.grip.inner_beam =
true;
151 data->
gripper.grip.outer_beam =
true;
153 if (!(
digin & 0x10)) {
154 data->
gripper.grip.left_contact =
true;
156 if (!(
digin & 0x20)) {
157 data->
gripper.grip.right_contact =
true;
163 if ((gripState & 0x10) && (gripState & 0x20) && !(gripState & 0x40)) {
168 }
else if (gripState & 0x40) {
173 if (gripState & 0x10) {
175 }
else if (gripState & 0x20) {
178 }
else if (gripState & 0x10) {
180 data->
gripper.lift.position = 1.0f;
182 }
else if (gripState & 0x20) {
184 data->
gripper.lift.position = 0.0f;
214 data->
dio.bits =
static_cast<unsigned int>(this->
digin);
219 data->
aio.voltages_count =
static_cast<unsigned char>(1);
223 data->
aio.voltages.clear();
224 data->
aio.voltages.push_back((this->
analog / 255.0) * 5.0);
234 diff2 = -(from + 4096 - to);
237 diff2 = 4096 - from + to;
239 return abs(diff1) <
abs(diff2) ? diff1 : diff2;
248 std::stringstream front_bumper_info;
249 for (
int i = 0; i < 5; i++) {
250 front_bumper_info <<
" " <<
253 ROS_DEBUG(
"Front bumpers:%s", front_bumper_info.str().c_str());
254 std::stringstream rear_bumper_info;
255 for (
int i = 0; i < 5; i++) {
256 rear_bumper_info <<
" " <<
259 ROS_DEBUG(
"Rear bumpers:%s", rear_bumper_info.str().c_str());
262 std::stringstream status_info;
263 for (i = 0; i < 11; i++) {
264 status_info <<
" " <<
265 static_cast<int>((
status >> (7 - i) ) & 0x01);
267 ROS_DEBUG(
"status:%s", status_info.str().c_str());
268 std::stringstream digin_info;
269 for (i = 0; i < 8; i++) {
271 static_cast<int>((
digin >> (7 - i) ) & 0x01);
273 ROS_DEBUG(
"digin:%s", digin_info.str().c_str());
274 std::stringstream digout_info;
275 for (i = 0; i < 8; i++) {
276 digout_info <<
" " <<
277 static_cast<int>((
digout >> (7 - i) ) & 0x01);
279 ROS_DEBUG(
"digout:%s", digout_info.str().c_str());
280 ROS_DEBUG(
"battery: %d compass: %d sonarreadings: %d\n",
battery,
283 ROS_DEBUG(
"angle: %d lvel: %d rvel: %d control: %d\n",
angle,
lvel,
296 std::stringstream sonar_info;
298 sonar_info <<
" " <<
static_cast<int>(
sonars[i]);
300 ROS_DEBUG(
"Sonars: %s", sonar_info.str().c_str());
308 for (
int ii = 0; ii < 6; ii++) {
318 ROS_DEBUG(
" |\tSpeed\tHome\tMin\tCentre\tMax\tTicks/90\n");
328 uint16_t newxpos, newypos;
331 cnt +=
sizeof(
unsigned char);
343 newxpos = ((buffer[cnt] | (buffer[cnt + 1] << 8)) &
346 if (
xpos != INT_MAX) {
349 if (
abs(change) > 100) {
350 ROS_DEBUG(
"invalid odometry change [%d]; odometry values are tainted", change);
358 cnt +=
sizeof(int16_t);
360 newypos = ((buffer[cnt] | (buffer[cnt + 1] << 8)) &
363 if (
ypos != INT_MAX) {
366 if (
abs(change) > 100) {
367 ROS_DEBUG(
"invalid odometry change [%d]; odometry values are tainted", change);
375 cnt +=
sizeof(int16_t);
378 rint(((int16_t)(buffer[cnt] | (buffer[cnt + 1] << 8))) *
380 cnt +=
sizeof(int16_t);
383 rint(((int16_t)(buffer[cnt] | (buffer[cnt + 1] << 8))) *
385 cnt +=
sizeof(int16_t);
388 rint(((int16_t)(buffer[cnt] | (buffer[cnt + 1] << 8))) *
390 cnt +=
sizeof(int16_t);
393 cnt +=
sizeof(
unsigned char);
398 cnt +=
sizeof(
unsigned char);
402 cnt +=
sizeof(
unsigned char);
405 rint(((int16_t)(buffer[cnt] | (buffer[cnt + 1] << 8))) *
407 cnt +=
sizeof(int16_t);
409 ptu = (buffer[cnt] | (buffer[cnt + 1] << 8));
412 cnt +=
sizeof(int16_t);
415 if (buffer[cnt] != 255 && buffer[cnt] != 0 && buffer[cnt] != 181) {
416 compass = (buffer[cnt] - 1) * 2;
418 cnt +=
sizeof(
unsigned char);
420 unsigned char numSonars = buffer[cnt];
421 cnt +=
sizeof(
unsigned char);
426 for (
unsigned char i = 0; i < numSonars; i++) {
427 unsigned char sonarIndex = buffer[cnt + i * (
sizeof(
unsigned char) +
sizeof(uint16_t))];
428 if ((sonarIndex + 1) > maxSonars) {maxSonars = sonarIndex + 1;}
433 uint16_t * newSonars =
new uint16_t[maxSonars];
439 sonarreadings = maxSonars;
443 for (
unsigned char i = 0; i < numSonars; i++) {
444 sonars[buffer[cnt]] =
static_cast<uint16_t
>(
445 rint((buffer[cnt + 1] | (buffer[cnt + 2] << 8)) *
447 cnt +=
sizeof(
unsigned char) +
sizeof(uint16_t);
451 timer = (buffer[cnt] | (buffer[cnt + 1] << 8));
452 cnt +=
sizeof(int16_t);
455 cnt +=
sizeof(
unsigned char);
458 cnt +=
sizeof(
unsigned char);
461 cnt +=
sizeof(
unsigned char);
478 unsigned char type = buffer[1];
481 ROS_ERROR(
"Attempt to parse non SERAUX packet as serial data.\n");
485 int len =
static_cast<int>(buffer[0]) - 3;
495 for (ix = (len > 18 ? len - 17 : 2); ix <= len - 8; ix++) {
496 if (buffer[ix] == 255) {
500 if (len < 10 || ix > len - 8) {
501 ROS_ERROR(
"Failed to get a full blob tracking packet.\n");
506 if (buffer[ix + 1] ==
'S') {
508 ROS_DEBUG(
"Tracking color (RGB): %d %d %d\n" 509 " with variance: %d %d %d\n",
510 buffer[ix + 2], buffer[ix + 3], buffer[ix + 4],
511 buffer[ix + 5], buffer[ix + 6], buffer[ix + 7]);
512 blobcolor = buffer[ix + 2] << 16 | buffer[ix + 3] << 8 | buffer[ix + 4];
517 if (buffer[ix + 1] ==
'M') {
531 ROS_ERROR(
"Unknown blob tracker packet type: %c\n", buffer[ix + 1]);
545 int len =
static_cast<int>(buffer[0] - 3);
547 unsigned char type = buffer[1];
550 ROS_ERROR(
"Attempt to parse non GYRO packet as gyro data.\n");
555 ROS_DEBUG(
"Couldn't get gyro measurement count");
560 int count =
static_cast<int>(buffer[2]);
563 if ((len - 1) != (count * 3)) {
564 ROS_DEBUG(
"Mismatch between gyro measurement count and packet length");
577 for (
int i = 0; i < count; i++) {
578 rate = (uint16_t)(buffer[bufferpos++]);
579 rate |= buffer[bufferpos++] << 8;
584 int32_t average_rate =
static_cast<int32_t
>(rint(ratesum / static_cast<float>(count)));
592 int length =
static_cast<int>(buffer[0]) - 2;
594 if (buffer[1] !=
ARMPAC) {
595 ROS_ERROR(
"Attempt to parse a non ARM packet as arm data.\n");
599 if (length < 1 || length != 9) {
600 ROS_DEBUG(
"ARMpac length incorrect size");
604 unsigned char status = buffer[2];
607 unsigned char motionStatus = buffer[3];
608 if (motionStatus & 0x01) {
611 if (motionStatus & 0x02) {
614 if (motionStatus & 0x04) {
617 if (motionStatus & 0x08) {
620 if (motionStatus & 0x10) {
623 if (motionStatus & 0x20) {
633 int length =
static_cast<int>(buffer[0]) - 2;
635 ROS_ERROR(
"Attempt to parse a non ARMINFO packet as arm info.\n");
650 armVersionString =
reinterpret_cast<char *
>(calloc(length + 1,
sizeof(
char)));
unsigned char armJointPos[6]
p2os_msgs::SonarArray sonar
Container for sonar data.
std::string odom_frame_id
void ParseGyro(unsigned char *buffer)
void ParseArmInfo(unsigned char *buffer)
p2os_msgs::AIO aio
Analog In/Out.
unsigned char motors_enabled
p2os_msgs::GripperState gripper
Provides the state of the gripper.
geometry_msgs::TransformStamped odom_trans
Transformed odometry frame.
void ParseSERAUX(unsigned char *buffer)
int PositionChange(uint16_t, uint16_t)
void ParseStandard(unsigned char *buffer)
unsigned char sonarreadings
RobotParams_t PlayerRobotParams[]
double min(double a, double b)
p2os_msgs::BatteryState batt
Provides the battery voltage.
void FillStandard(ros_p2os_data_t *data)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
unsigned char armNumJoints
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
double max(double a, double b)
void ParseArm(unsigned char *buffer)
p2os_msgs::MotorState motors
Provides the state of the motors (enabled or disabled)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
nav_msgs::Odometry position
Provides the position of the robot.
std::string base_link_frame_id
p2os_msgs::DIO dio
Digital In/Out.
double armJointPosRads[6]