33 batt_pub_(n.advertise<p2os_msgs::BatteryState>(
"battery_state", 1000),
89 n_private.
param(
"max_xaccel", spd, 0.0);
92 n_private.
param(
"max_xdecel", spd, 0.0);
95 n_private.
param(
"max_yawaccel", spd, 0.0);
98 n_private.
param(
"max_yawdecel", spd, 0.0);
153 packet.
Build(command, 4);
168 unsigned char grip_val = (
unsigned char)
gripper_state_.grip.state;
169 unsigned char grip_command[4];
174 grip_command[2] = grip_val;
176 grip_packet.Build(grip_command, 4);
180 unsigned char lift_val = (
unsigned char)
gripper_state_.lift.state;
181 unsigned char lift_command[4];
186 lift_command[2] = lift_val;
188 lift_packet.Build(lift_command, 4);
195 if (fabs(msg->linear.x -
cmdvel_.linear.x) > 0.01 ||
196 fabs(msg->angular.z -
cmdvel_.angular.z) > 0.01)
199 ROS_DEBUG(
"new speed: [%0.2f,%0.2f](%0.3f)", msg->linear.x * 1e3, msg->angular.z,
205 if (veldur.
toSec() > 2.0 &&
206 ((fabs(
cmdvel_.linear.x) > 0.01) || (fabs(
cmdvel_.angular.z) > 0.01)))
222 uint16_t absSpeedDemand, absturnRateDemand;
223 unsigned char motorcommand[4];
226 int vx =
static_cast<int>(
cmdvel_.linear.x * 1e3);
227 int va =
static_cast<int>(rint(
RTOD(
cmdvel_.angular.z)));
230 motorcommand[0] =
VEL;
233 absSpeedDemand =
static_cast<uint16_t
>(
abs(vx));
236 motorcommand[2] = absSpeedDemand & 0x00FF;
237 motorcommand[3] = (absSpeedDemand & 0xFF00) >> 8;
239 ROS_WARN(
"speed demand thresholded! (true: %u, max: %u)", absSpeedDemand, motor_max_speed);
240 motorcommand[2] = motor_max_speed & 0x00FF;
241 motorcommand[3] = (motor_max_speed & 0xFF00) >> 8;
244 motorpacket.
Build(motorcommand, 4);
247 motorcommand[0] =
RVEL;
250 absturnRateDemand =
static_cast<uint16_t
>((va >= 0) ? va : (-1 * va));
253 motorcommand[2] = absturnRateDemand & 0x00FF;
254 motorcommand[3] = (absturnRateDemand & 0xFF00) >> 8;
256 ROS_WARN(
"Turn rate demand threshholded!");
261 motorpacket.
Build(motorcommand, 4);
274 int bauds[] = {B9600, B38400, B19200, B115200, B57600};
275 int numbauds =
sizeof(bauds);
284 bool sent_close =
false;
294 psos_state = NO_SYNC;
296 char name[20], type[20], subtype[20];
305 O_RDWR | O_SYNC | O_NONBLOCK, S_IRUSR | S_IWUSR)) < 0)
311 if (tcgetattr(this->
psos_fd, &term) < 0) {
319 cfsetispeed(&term, bauds[currbaud]);
320 cfsetospeed(&term, bauds[currbaud]);
322 if (tcsetattr(this->
psos_fd, TCSAFLUSH, &term) < 0) {
329 if (tcflush(this->
psos_fd, TCIOFLUSH) < 0) {
336 if ((flags = fcntl(this->
psos_fd, F_GETFL)) < 0) {
344 int num_sync_attempts = 3;
345 while (psos_state != READY) {
346 switch (psos_state) {
349 packet.
Build(&command, 1);
353 case AFTER_FIRST_SYNC:
354 ROS_INFO(
"turning off NONBLOCK mode...");
355 if (fcntl(this->
psos_fd, F_SETFL, flags ^ O_NONBLOCK) < 0) {
362 packet.
Build(&command, 1);
365 case AFTER_SECOND_SYNC:
367 packet.
Build(&command, 1);
371 ROS_WARN(
"P2OS::Setup():shouldn't be here...");
376 if (receivedpacket.
Receive(this->psos_fd)) {
377 if ((psos_state == NO_SYNC) && (num_sync_attempts >= 0)) {
383 if (++currbaud < numbauds) {
384 cfsetispeed(&term, bauds[currbaud]);
385 cfsetospeed(&term, bauds[currbaud]);
386 if (tcsetattr(this->
psos_fd, TCSAFLUSH, &term) < 0) {
393 if (tcflush(this->
psos_fd, TCIOFLUSH) < 0) {
399 num_sync_attempts = 3;
407 switch (receivedpacket.
packet[3]) {
410 psos_state = AFTER_FIRST_SYNC;
414 psos_state = AFTER_SECOND_SYNC;
426 packet.
Build(&command, 1);
430 tcflush(this->
psos_fd, TCIFLUSH);
431 psos_state = NO_SYNC;
437 if (psos_state != READY) {
439 ROS_INFO(
"Couldn't synchronize with P2OS.\n" 440 " Most likely because the robot is not connected %s %s",
441 this->
psos_use_tcp ?
"to the ethernet-serial bridge device " :
"to the serial port",
449 cnt += snprintf(name,
sizeof(name),
"%s", &receivedpacket.
packet[cnt]);
451 cnt += snprintf(type,
sizeof(type),
"%s", &receivedpacket.
packet[cnt]);
453 cnt += snprintf(subtype,
sizeof(subtype),
"%s", &receivedpacket.
packet[cnt]);
456 std::string hwID = std::string(name) +
": " + std::string(type) +
"/" + std::string(subtype);
460 packet.
Build(&command, 1);
464 packet.
Build(&command, 1);
468 ROS_INFO(
"Done.\n Connected to %s, a %s %s", name, type, subtype);
479 if (i == PLAYER_NUM_ROBOT_TYPES) {
480 ROS_WARN(
"P2OS: Warning: couldn't find parameters for this robot; " 502 unsigned char accel_command[4];
504 accel_command[0] =
SETA;
505 accel_command[1] =
ARGINT;
508 accel_packet.
Build(accel_command, 4);
513 accel_command[0] =
SETA;
517 accel_packet.
Build(accel_command, 4);
521 accel_command[0] =
SETRA;
522 accel_command[1] =
ARGINT;
525 accel_packet.
Build(accel_command, 4);
529 accel_command[0] =
SETRA;
533 accel_packet.
Build(accel_command, 4);
540 unsigned char pid_command[4];
542 pid_command[0] =
ROTKP;
544 pid_command[2] = this->
rot_kp & 0x00FF;
545 pid_command[3] = (this->
rot_kp & 0xFF00) >> 8;
546 pid_packet.
Build(pid_command, 4);
550 pid_command[0] =
ROTKV;
552 pid_command[2] = this->
rot_kv & 0x00FF;
553 pid_command[3] = (this->
rot_kv & 0xFF00) >> 8;
554 pid_packet.
Build(pid_command, 4);
558 pid_command[0] =
ROTKI;
560 pid_command[2] = this->
rot_ki & 0x00FF;
561 pid_command[3] = (this->
rot_ki & 0xFF00) >> 8;
562 pid_packet.
Build(pid_command, 4);
568 pid_command[2] = this->
trans_kp & 0x00FF;
569 pid_command[3] = (this->
trans_kp & 0xFF00) >> 8;
570 pid_packet.
Build(pid_command, 4);
576 pid_command[2] = this->
trans_kv & 0x00FF;
577 pid_command[3] = (this->
trans_kv & 0xFF00) >> 8;
578 pid_packet.
Build(pid_command, 4);
584 pid_command[2] = this->
trans_ki & 0x00FF;
585 pid_command[3] = (this->
trans_ki & 0xFF00) >> 8;
586 pid_packet.
Build(pid_command, 4);
598 ROS_INFO(
"ignoring bumpstall value %d; should be 0, 1, 2, or 3",
603 unsigned char bumpstall_command[4];
605 bumpstall_command[1] =
ARGINT;
606 bumpstall_command[2] = (
unsigned char)this->
bumpstall;
607 bumpstall_command[3] = 0;
608 bumpstall_packet.
Build(bumpstall_command, 4);
625 unsigned char command[20], buffer[20];
632 memset(buffer, 0, 20);
639 packet.
Build(command, 1);
644 packet.
Build(command, 1);
698 pthread_testcancel();
699 if (packet.
Receive(this->psos_fd)) {
700 ROS_ERROR(
"RunPsosThread(): Receive errored");
704 const bool packet_check =
706 (packet.
packet[3] == 0x30 || packet.
packet[3] == 0x31 ||
708 packet.
packet[3] == 0x34);
719 }
else if (ser_aux) {
722 int len = packet.
packet[2] - 3;
724 ROS_ERROR(
"PTZ got a message, but alread has the complete packet.");
726 for (
int i = 4; i < 4 + len; ++i) {
748 if (voltage < 11.0) {
749 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
"battery voltage critically low");
750 }
else if (voltage < 11.75) {
751 stat.
summary(diagnostic_msgs::DiagnosticStatus::WARN,
"battery voltage getting low");
752 }
else {stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"battery voltage OK");}
754 stat.
add(
"voltage", voltage);
760 stat.
summary(diagnostic_msgs::DiagnosticStatus::ERROR,
762 }
else {stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
"no wheel stall");}
771 unsigned char p2oscommand[4];
778 p2oscommand[0] =
SETO;
780 pkt.
Build(p2oscommand, 2);
782 ROS_INFO(
"resetting raw positions");
796 packet.
Build(command, 4);
815 packet.
Build(command, 4);
834 result = result * pos;
835 if ((joint >= 0) && (joint <= 2)) {
854 if ((joint >= 0) && (joint <= 2)) {
859 if (val < sippacket->armJoints[joint].
min) {
862 return static_cast<int>(round(val));
883 double degs =
RTOD(speed);
885 double ticksPerSec = degs * ticksPerDeg;
886 double secsPerTick = 1000.0f / ticksPerSec;
888 if (secsPerTick > 127) {
890 }
else if (secsPerTick < 1) {
899 double ticksPerSec = 1.0 / (
static_cast<double>(msecs) / 1000.0);
901 double degs = ticksPerSec / ticksPerDeg;
902 double rads =
DTOR(degs);
913 packet.
Build(&command, 1);
std::string psos_tcp_host
double TicksToDegrees(int joint, unsigned char ticks)
Convert ticks to degrees.
diagnostic_updater::Updater diagnostic_
void initialize_robot_params(void)
int motor_max_speed
Maximum motor speed in Meters per second.
unsigned char packet[packet_len]
p2os_msgs::PTZState getCurrentState()
void publish(const boost::shared_ptr< M > &message) const
void ToggleMotorPower(unsigned char val)
Toggle motors on/off.
ros::Publisher mstate_pub_
int SendReceive(P2OSPacket *pkt, bool publish_data=true)
p2os_msgs::MotorState cmdmotor_state_
Motor state publisher.
void summary(unsigned char lvl, const std::string s)
p2os_msgs::SonarArray sonar
Container for sonar data.
double RadsPerSectoSecsPerTick(int joint, double speed)
Convert radians per second to radians per encoder tick.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string odom_frame_id
#define DEFAULT_P2OS_TCP_REMOTE_PORT
bool use_sonar_
Use the sonar array?
void setHardwareID(const std::string &hwid)
unsigned char RadiansToTicks(int joint, double rads)
Convert radians to ticks.
int16_t motor_max_rot_decel
Minimum rotational acceleration in Meters per second per second.
void add(const std::string &name, TaskFunction f)
p2os_msgs::AIO aio
Analog In/Out.
virtual void publish(const boost::shared_ptr< T > &message)
int16_t motor_max_trans_decel
Minimum translational acceleration in Meters per second per second.
ros::NodeHandle n
Node Handler used for publication of data.
void check_voltage(diagnostic_updater::DiagnosticStatusWrapper &stat)
std::string psos_serial_port
int joystick
Use Joystick?
void gripperCallback(const p2os_msgs::GripperStateConstPtr &msg)
std::string base_link_frame_id
#define DEFAULT_P2OS_PORT
p2os_msgs::GripperState gripper
Provides the state of the gripper.
geometry_msgs::TransformStamped odom_trans
Transformed odometry frame.
ros::Publisher sonar_pub_
void check_and_set_gripper_state()
tf::TransformBroadcaster odom_broadcaster
int16_t motor_max_rot_accel
Maximum rotational acceleration in radians per second per second.
void ParseStandard(unsigned char *buffer)
#define PLAYER_NUM_ROBOT_TYPES
void putOnBuf(unsigned char c)
diagnostic_updater::DiagnosedPublisher< p2os_msgs::BatteryState > batt_pub_
int16_t motor_max_trans_accel
Maximum translational acceleration in Meters per second per second.
#define MOTOR_DEF_MAX_TURNSPEED
ROSLIB_DECL std::string command(const std::string &cmd)
int Build(unsigned char *data, unsigned char datasize)
int bumpstall
Stall I hit a wall?
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
p2os_msgs::GripperState gripper_state_
Gripper state publisher.
void callback(const p2os_msgs::PTZStateConstPtr &msg)
ros::Publisher grip_state_pub_
RobotParams_t PlayerRobotParams[]
int Setup()
Setup the robot for use. Communicates with the robot directly.
double min(double a, double b)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
P2OSNode(ros::NodeHandle n)
P2OS robot driver node.
ros::Subscriber ptz_cmd_sub_
#define P2OS_CYCLETIME_USEC
void cmdmotor_state(const p2os_msgs::MotorStateConstPtr &)
ros::Subscriber cmdvel_sub_
p2os_msgs::BatteryState batt
Provides the battery voltage.
int motor_max_turnspeed
Maximum turn speed in radians per second.
int Shutdown()
Prepare for shutdown.
double lastPulseTime
Last time the node received or sent a pulse.
void FillStandard(ros_p2os_data_t *data)
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
ros::Subscriber gripper_sub_
unsigned char armNumJoints
ros::Subscriber cmdmstate_sub_
void StandardSIPPutData(ros::Time ts)
void ToggleSonarPower(unsigned char val)
#define DEFAULT_P2OS_TCP_REMOTE_HOST
#define MOTOR_DEF_MAX_SPEED
std::string odom_frame_id
void add(const std::string &key, const T &val)
double TicksToRadians(int joint, unsigned char ticks)
Convert ticks to radians.
ros_p2os_data_t p2os_data
sensor data container
geometry_msgs::Twist cmdvel_
Command Velocity subscriber.
p2os_msgs::MotorState motors
Provides the state of the motors (enabled or disabled)
double SecsPerTicktoRadsPerSec(int joint, double secs)
Convert Seconds per encoder tick to radians per second.
unsigned char DegreesToTicks(int joint, double degrees)
convert degrees to ticks
void check_and_set_motor_state()
void cmdvel_cb(const geometry_msgs::TwistConstPtr &)
ros::Publisher ptz_state_pub_
nav_msgs::Odometry position
Provides the position of the robot.
int direct_wheel_vel_control
Control wheel velocities individually?
void check_stall(diagnostic_updater::DiagnosticStatusWrapper &stat)
std::string base_link_frame_id
p2os_msgs::DIO dio
Digital In/Out.