RobotSimulation/pick_and_place/ROS/src/niryo_one_ros/niryo_one_driver/src/ros_interface.cpp
bool RosInterface::callbackActivateLearningMode(niryo_one_msgs::SetInt::Request &req, niryo_one_msgs::SetInt::Response &res)
{
    if (comm->isCalibrationInProgress()) {
        res.status = 400;
        res.message = "You can't activate/deactivate learning mode during motors calibration";
        return true;
    }

    if (calibration_needed == 1 || !comm->isConnectionOk()) { // if can or dxl is disconnected, only allow to activate learning mode
        learning_mode_on = true;
    }
    else {
        learning_mode_on = req.value; 
    }
    
    // reset controller if learning mode -> OFF
    // we want motors to start where they physically are, not from the last command
    if (!learning_mode_on) {
        *(flag_reset_controllers) = true;
        ros::Duration(0.05).sleep();
    }
    
    comm->activateLearningMode(learning_mode_on);
    
    // publish one time
    std_msgs::Bool msg;
    msg.data = learning_mode_on;
    learning_mode_publisher.publish(msg);
   
    res.status = 200;
    res.message = (learning_mode_on) ? "Activating learning mode" : "Deactivating learning mode";
    return true;
}
/*
 * Deactivating learning mode (= activating motors) is possible only if motors are calibrated
 * Activating learning mode is also possible when waiting for calibration
 */
Deactivating learning mode (= activating motors) is possible only if motors are calibrated
Activating learning mode is also possible when waiting for calibration
Deactivating learning mode ( = activating motors ) is possible only if motors are calibrated Activating learning mode is also possible when waiting for calibration
bool RosInterface::callbackActivateLearningMode(niryo_one_msgs::SetInt::Request &req, niryo_one_msgs::SetInt::Response &res)
{
    if (comm->isCalibrationInProgress()) {
        res.status = 400;
        res.message = "You can't activate/deactivate learning mode during motors calibration";
        return true;
    }
    if (calibration_needed == 1 || !comm->isConnectionOk()) { 
        learning_mode_on = true;
    }
    else {
        learning_mode_on = req.value; 
    }
    if (!learning_mode_on) {
        *(flag_reset_controllers) = true;
        ros::Duration(0.05).sleep();
    }
    comm->activateLearningMode(learning_mode_on);
    std_msgs::Bool msg;
    msg.data = learning_mode_on;
    learning_mode_publisher.publish(msg);
    res.status = 200;
    res.message = (learning_mode_on) ? "Activating learning mode" : "Deactivating learning mode";
    return true;
}
bool RosInterface :: callbackActivateLearningMode ( niryo_one_msgs :: SetInt :: Request & req , niryo_one_msgs :: SetInt :: Response & res ) { if ( comm -> isCalibrationInProgress ( ) ) { res . status = 400 ; res . message = " " ; return true ; } if ( calibration_needed == 1 || ! comm -> isConnectionOk ( ) ) { learning_mode_on = true ; } else { learning_mode_on = req . value ; } if ( ! learning_mode_on ) { * ( flag_reset_controllers ) = true ; ros :: Duration ( 0.05 ) . sleep ( ) ; } comm -> activateLearningMode ( learning_mode_on ) ; std_msgs :: Bool msg ; msg . data = learning_mode_on ; learning_mode_publisher . publish ( msg ) ; res . status = 200 ; res . message = ( learning_mode_on ) ? " " : " " ; return true ; }
Deactivating learning mode (= activating motors) is possible only if motors are calibrated
 Activating learning mode is also possible when waiting for calibration
Deactivating learning mode ( = activating motors ) is possible only if motors are calibrated Activating learning mode is also possible when waiting for calibration
// if can or dxl is disconnected, only allow to activate learning mode // reset controller if learning mode -> OFF // we want motors to start where they physically are, not from the last command // publish one time