4 #include "std_srvs/Trigger.h" 5 #include "geometry_msgs/Twist.h" 6 #include "raspicat/MotorFreqs.h" 7 #include "raspicat/TimedMotion.h" 8 #include <nav_msgs/Odometry.h> 13 #include "sensor_msgs/Imu.h" 21 bool callbackOn(std_srvs::Trigger::Request&, std_srvs::Trigger::Response&);
22 bool callbackOff(std_srvs::Trigger::Request&, std_srvs::Trigger::Response&);
23 bool callbackTimedMotion(raspicat::TimedMotion::Request&, raspicat::TimedMotion::Response&);
24 void callbackRaw(
const raspicat::MotorFreqs::ConstPtr& msg);
34 geometry_msgs::Twist
vel;
41 std::ofstream ofs(
"/dev/rtmotoren0");
45 ofs << (on ?
'1' :
'0') << std::endl;
52 std::ofstream ofsL(
"/dev/rtmotor_raw_l0");
53 std::ofstream ofsR(
"/dev/rtmotor_raw_r0");
54 if( (not ofsL.is_open()) or (not ofsR.is_open()) ){
55 ROS_ERROR(
"Cannot open /dev/rtmotor_raw_{l,r}0");
59 ofsL << left << std::endl;
60 ofsR << right << std::endl;
69 bool callbackOn(std_srvs::Trigger::Request& request, std_srvs::Trigger::Response& response)
74 response.message =
"ON";
75 response.success =
true;
79 bool callbackOff(std_srvs::Trigger::Request& request, std_srvs::Trigger::Response& response)
84 response.message =
"OFF";
85 response.success =
true;
89 bool callbackTimedMotion(raspicat::TimedMotion::Request& request, raspicat::TimedMotion::Response& response)
92 ROS_INFO(
"Motors are not enpowered");
96 std::ofstream ofs(
"/dev/rtmotor0");
97 if(not ofs.is_open()){
102 ofs << request.left_hz <<
' ' << request.right_hz <<
' ' 103 << request.duration_ms << std::endl;
105 response.success =
true;
111 setFreqs(msg->left_hz, msg->right_hz);
116 vel.linear.x = msg->linear.x;
119 vel.angular.z = msg->angular.z;
121 double forward_hz = 50000.0*msg->linear.x/(19.0*3.141592);
122 double rot_hz = 6975.0*msg->angular.z/(19.0*3.141592);
123 setFreqs((
int)round(forward_hz-rot_hz), (
int)round(forward_hz+rot_hz));
135 vel.angular.z = round(msg->angular_velocity.z * 20)/20;
142 double dt = cur_time.
toSec() - send_time.
toSec();
152 geometry_msgs::TransformStamped odom_trans;
154 odom_trans.header.frame_id =
"odom";
155 odom_trans.child_frame_id =
"base_link";
157 odom_trans.transform.translation.x =
odom_x;
158 odom_trans.transform.translation.y =
odom_y;
159 odom_trans.transform.translation.z = 0.0;
163 odom_trans.transform.rotation.x = q.x();
164 odom_trans.transform.rotation.y = q.y();
165 odom_trans.transform.rotation.z = q.z();
166 odom_trans.transform.rotation.w = q.w();
170 nav_msgs::Odometry odom;
172 odom.header.frame_id =
"odom";
173 odom.child_frame_id =
"base_link";
175 odom.pose.pose.position.x =
odom_x;
176 odom.pose.pose.position.y =
odom_y;
177 odom.pose.pose.position.z = 0.0;
178 odom_trans.transform.rotation = odom_quat;
179 odom.pose.pose.orientation = odom_quat;
181 odom.twist.twist.linear.x =
vel.linear.x;
182 odom.twist.twist.linear.y = 0.0;
183 odom.twist.twist.angular.z =
vel.angular.z;
189 int main(
int argc,
char **argv)
193 init(argc,argv,
"motors");
void setRPY(const tf2Scalar &roll, const tf2Scalar &pitch, const tf2Scalar &yaw)
nav_msgs::Odometry send_odom(void)
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
bool callbackTimedMotion(raspicat::TimedMotion::Request &, raspicat::TimedMotion::Response &)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
bool callbackOff(std_srvs::Trigger::Request &, std_srvs::Trigger::Response &)
void setFreqs(int left, int right)
ROSCPP_DECL void spinOnce()
void callbackCmdvel(const geometry_msgs::Twist::ConstPtr &msg)
bool callbackOn(std_srvs::Trigger::Request &, std_srvs::Trigger::Response &)
void callbackRaw(const raspicat::MotorFreqs::ConstPtr &msg)
void callback9Axis(const sensor_msgs::Imu::ConstPtr &msg)