21   const double epsilon = 0.0001;
    22   if ( std::abs(wz) < epsilon ) {
    24   } 
else if ( (std::abs(vx) < epsilon ) && ( wz > epsilon ) ) {
    26   } 
else if ((std::abs(vx) < epsilon ) && ( wz < -1*epsilon ) ) {
    29     radius = (short)(vx * 1000.0
f / wz);
    32     speed = (short)(1000.0
f * std::min(vx + 
bias * wz / 2.0
f, vx - 
bias * wz / 2.0
f));
    34     speed = (short)(1000.0
f * std::max(vx + 
bias * wz / 2.0
f, vx - 
bias * wz / 2.0
f));
    42     Rb2Vw( 
const int wheelToWheelInMM = 230 ) : half_wheel_2_wheel(wheelToWheelInMM/2) {}
    44     void getVW( 
const int leftWheelVelocity, 
const int rightWheelVelocity, 
int & linearSpeed, 
int & rotationalSpeedInDegree )
    46         if( std::abs( static_cast<float>(leftWheelVelocity ))
    47             > std::abs( static_cast<float>(rightWheelVelocity) ) )
    48             linearSpeed = leftWheelVelocity;
    50             linearSpeed = rightWheelVelocity;
    52         rotationalSpeedInDegree = ( rightWheelVelocity - leftWheelVelocity  ) * 180 / (half_wheel_2_wheel*2) / 3.14152;
    55     void getSR( 
const int leftWheelVelocity, 
const int rightWheelVelocity, 
int & desiredSpeed, 
int & desiredRadius )
    57         if( leftWheelVelocity == rightWheelVelocity )
    59             desiredSpeed    = leftWheelVelocity;
    62         else if( std::abs(static_cast<float>(leftWheelVelocity)) == std::abs(static_cast<float>(rightWheelVelocity)) )
    64             desiredSpeed = std::abs(static_cast<float>(leftWheelVelocity));
    65             if( leftWheelVelocity < rightWheelVelocity )    desiredRadius = +1;
    66             else                                            desiredRadius = -1;
    70             desiredRadius   = -(leftWheelVelocity+rightWheelVelocity)*half_wheel_2_wheel/(leftWheelVelocity-rightWheelVelocity);
    71             if( std::abs(static_cast<float>(leftWheelVelocity)) < std::abs(static_cast<float>(rightWheelVelocity)) )
    73                 desiredSpeed    = rightWheelVelocity;
    77                 desiredSpeed = leftWheelVelocity;
    83     void getWheelVelocity( 
const double & linearVelInMeter, 
const double & rotationalVelInRadian, 
double & leftWheelVel, 
double & rightWheelVel )
    85         leftWheelVel  = linearVelInMeter - rotationalVelInRadian * 
static_cast<double>( 
half_wheel_2_wheel ) * 0.001;
    86         rightWheelVel = linearVelInMeter + rotationalVelInRadian * 
static_cast<double>( 
half_wheel_2_wheel ) * 0.001;
    89     void update( 
const int desiredSpeed, 
const int desiredRadius, 
int & leftWheelVelocity, 
int & rightWheelVelocity )
    91         bool change_direction(
false);
    93         if( desiredSpeed == 0 && desiredRadius == 0 )
    95             leftWheelVelocity = 0;
    96             rightWheelVelocity = 0;
   100         if( desiredRadius == 0 )
   102             leftWheelVelocity   = desiredSpeed;
   103             rightWheelVelocity  = desiredSpeed;
   105         else if( desiredRadius == -1 || desiredRadius == +1 )
   107             leftWheelVelocity = -desiredRadius * desiredSpeed;
   108             rightWheelVelocity = desiredRadius * desiredSpeed;
   112             int radius( desiredRadius );
   116                 change_direction = 
true;
   119             int left( radius - half_wheel_2_wheel );
   120             int right( radius + half_wheel_2_wheel );
   122             if( change_direction )
   124                 leftWheelVelocity   = (desiredSpeed*right)/right;
   125                 rightWheelVelocity  = (desiredSpeed*left)/right;
   129                 leftWheelVelocity   = (desiredSpeed*left)/right;
   130                 rightWheelVelocity  = (desiredSpeed*right)/right;
   137 int main(
int argc, 
char **argv) {
   159   std::cout << 
"Reproduce the issue with slow motion command" << 
std::endl;
   165   int left_wheel_speed;
   166   int right_wheel_speed;
   168   printf(
"fw will generate left right wheel speed as [%d mm/sec | %d mm/sec] \n", left_wheel_speed, right_wheel_speed );
   170   double left_wheel_speed_in_meter;
   171   double right_wheel_speed_in_meter;
   172   int desire_speed, desired_radius;
   173   fw.
getWheelVelocity( vx, wz, left_wheel_speed_in_meter, right_wheel_speed_in_meter );
   174   printf(
"When you have vx(%f), wz(%f), robot have to generate left right wheel speed as %f, %f \n", vx, wz, left_wheel_speed_in_meter, right_wheel_speed_in_meter );
   175   fw.
getSR( left_wheel_speed_in_meter*1000, right_wheel_speed_in_meter*1000, desire_speed, desired_radius );
   176   printf(
"My quick code result for speed and radius are %d, %d \n", desire_speed, desired_radius );
   178   fw.
update( desire_speed, desired_radius, left_wheel_speed, right_wheel_speed );
   179   printf(
"fw will generate left right wheel speed as [%d mm/sec | %d mm/sec] \n", left_wheel_speed, right_wheel_speed );
   182   for( vx=-0.3;vx<0.3; vx+=0.001 )
   184           for( wz=-0.5;wz<0.5; wz += 0.1 )
   188                   fw.
getWheelVelocity( vx, wz, left_wheel_speed_in_meter, right_wheel_speed_in_meter );
   190                   err_l = left_wheel_speed - left_wheel_speed_in_meter*1000.0;
   191                   err_r = right_wheel_speed - right_wheel_speed_in_meter*1000.0;
   193                   if( fabs(err_l) > 2.5 || fabs(err_r) > 2.5 )
   195                           printf(
"something wrong [%f,%f] --> [%f,%f] [%d,%d][%f,%f]\n", vx, wz, 
speed, 
radius,
   196                                   left_wheel_speed, right_wheel_speed,
   197                                   left_wheel_speed_in_meter*1000.0, right_wheel_speed_in_meter*1000.0 );
   202   for( vx=-0.3;vx<0.3; vx+=0.001 )
   204           for( wz=-0.5;wz<0.5; wz += 0.1 )
   206                   fw.
getWheelVelocity( vx, wz, left_wheel_speed_in_meter, right_wheel_speed_in_meter );
   207                   fw.
getSR( left_wheel_speed_in_meter*1000, right_wheel_speed_in_meter*1000, desire_speed, desired_radius );
   208                   fw.
update( desire_speed, desired_radius, left_wheel_speed, right_wheel_speed );
   211                   err_l = left_wheel_speed - left_wheel_speed_in_meter*1000.0;
   212                   err_r = right_wheel_speed - right_wheel_speed_in_meter*1000.0;
   214                   if( fabs(err_l) > 2.5 || fabs(err_r) > 2.5 )
   216                           printf(
"something wrong [%f,%f] --> [%f,%f] [%d,%d][%f,%f]\n", vx, wz, 
speed, 
radius,
   217                                   left_wheel_speed, right_wheel_speed,
   218                                   left_wheel_speed_in_meter*1000.0, right_wheel_speed_in_meter*1000.0 );
 void update(const int desiredSpeed, const int desiredRadius, int &leftWheelVelocity, int &rightWheelVelocity)
void getVW(const int leftWheelVelocity, const int rightWheelVelocity, int &linearSpeed, int &rotationalSpeedInDegree)
void velocityCommand(const double &vx, const double &wz)
void getSR(const int leftWheelVelocity, const int rightWheelVelocity, int &desiredSpeed, int &desiredRadius)
Rb2Vw(const int wheelToWheelInMM=230)
void getWheelVelocity(const double &linearVelInMeter, const double &rotationalVelInRadian, double &leftWheelVel, double &rightWheelVel)
void f(int i) ecl_debug_throw_decl(StandardException)
int main(int argc, char **argv)