# How can I compute yaw rate from yaw angle?

Hi, I want to find a way to compute the yaw rate using the yaw angle. I have the idea of using the Euler forward method, however, I have encountered some issues like the fact that a full rotation is given by [0-pi, pi-0] and also considering multiple rotations (positives or negatives). The following code only works fine for 1 rotation.

```
void BebopVel::attitudeCallback(const bebop_msgs::Ardrone3PilotingStateAttitudeChanged &att_msg){
double yaw = normalize_angle(-att_msg.yaw);
std::cout << "Curr heading: " << yaw*180/M_PI << std::endl;
if(!got_first_att_msg_){
ROS_INFO("got first attitude message");
prev_attitude_time_ = att_msg.header.stamp;
prev_yaw_ = yaw;
got_first_att_msg_ = true;
return;
}
// get current values
curr_attitude_time_ = att_msg.header.stamp;
curr_yaw_ = yaw;
// compute time difference between samples
ros::Duration delta_t_attitude = curr_attitude_time_ - prev_attitude_time_;
double ts_attitude = delta_t_attitude.toSec(); // convert from ROS time to seconds
// compute yaw difference between samples
double delta_yaw = curr_yaw_ - prev_yaw_;
// compute yaw rate
yaw_rate_ = delta_yaw / ts_attitude;
// assign current values to previous
prev_attitude_time_ = curr_attitude_time_;
prev_yaw_ = curr_yaw_;
}
double BebopVel::normalize_angle(double ang){
// Normalizes the angle to be 0 to 2*pi
// It takes and returns radians.
double norm_ang = fmod(ang, 2.0*M_PI);
if(norm_ang < 0){
return norm_ang + 2.0*M_PI;
}
return norm_ang;
}
```

PD: Sorry for my poor English.

Well when you normalize the angle you are throwing away all the information about multiple rotations, is that function necessary in this context? Or, you could modify the function to return the number of rotations (forward or backward) then use that in the euler equation.