Joystick control via Mavlink

Hey everyone!
I am using Mavlink to upload missions to a quad and I want to have the ability to send joystick commands to it. looking through the PX4 documentation I saw this page:

and tried to use this Mavink command:
SET_POSITION_TARGET_GLOBAL_INT.
I send the command but according to the explanation at more than 2 Hz but I still can’t switch the drone to OFFBOARD mode.
This is the C++ function I am using to send the command to the controller:

int sendCommandsToPX4::setPositionTarget(float vx, float vy, float vz, float body_yaw) {
__mavlink_set_position_target_global_int_t com = {0};
com.target_system = this->ai->system_id;
com.target_component = this->ai->autopilot_id;
com.time_boot_ms = this->ai->get_time_usec();
com.coordinate_frame = MAV_FRAME_GLOBAL_INT;
com.type_mask = 0b010111000111;
com.vx = vx;
com.vy = vy;
com.vz = vz;

// Encode
mavlink_message_t message;
mavlink_msg_set_position_target_global_int_encode(this->ai->system_id, this->ai->companion_id, &message, &com);

// Send the message
int len = this->ai->port->write_message(message);
return len;

}