MIPI - Physical Interface for MIDI Files
Loading...
Searching...
No Matches
Control::Controller Class Reference

#include <controller.h>

Inheritance diagram for Control::Controller:
Inheritance graph
Collaboration diagram for Control::Controller:
Collaboration graph

Public Member Functions

 Controller ()
 Standalone Class for Controlling a UR3e. Typically reads data from .mipi files for plaback on a piano. Exposes various services for control.
 
 ~Controller ()
 Standard Destructor for Controller Class.
 

Private Member Functions

General Methods

Methods used throughout the class for various purposes

void sendTwistMsg (double x, double y, double z, double angular_x=0.0, double angular_y=0.0, double angular_z=0.0)
 A convenience method that neatly packs up a twist messge and publishes it to the UR_Driver.
 
void sendJointJog (double shoulder_lift, double elbow, double wrist_1, double wrist_2, double wrist_3, double shoulder_pan)
 A wrapper for sending joint jog commands for direct joint velocity control.
 
void sendJointJog (std::vector< double > vel)
 A secondary wrapper for the sending Joint Jog commands that takes a vector instead of individual velocities.
 
void sendVector (const vector3 &vec)
 The public method for sending translational End Effector vector commands to the UR3e.
 
void sendStop ()
 A simple helper method for immediately sending stop to the UR3e.
 
int activeTrackDebug (vector3 target, bool x=false, bool y=false, bool z=false)
 A method for enabling "activeTrack" mode, allowing for live visual servoing following a topic.
 
Startup & Shutdown Sequence

Functions related to the startup and shutdown sequence of the controller

void startup ()
 The startup sequence that moves the robot into the starting position for playing.
 
Subscriber Callbacks

All Subscriber callbacks that the Controller Class uses

void debug_target_callback (const geometry_msgs::msg::Point::SharedPtr msg)
 Callback function for catching the debug subscriber, used to activate activeTrack.
 
void key_positions_callback (const geometry_msgs::msg::PoseArray::SharedPtr msg)
 Subscriber Callback that obtains the key positions from the.
 
void joint_state_callback (const sensor_msgs::msg::JointState::SharedPtr msg)
 Subscriber Callback that obtains the joint state of the robot.
 
Service Callbacks

All Service callbacks that the Controller Class uses

void load_callback (const std::shared_ptr< jamc::srv::Load::Request > request, std::shared_ptr< jamc::srv::Load::Response > response)
 Callback function for the Load Service, used to load .mipi files and select which instrument channel.
 
void time_scale_callback (const std::shared_ptr< jamc::srv::TimeScale::Request > request, std::shared_ptr< jamc::srv::TimeScale::Response > response)
 Callback function for the TimeScale Service, used to set the time scaling factor for playback.
 
void play_pause_callback (const std::shared_ptr< jamc::srv::Func::Request > request, std::shared_ptr< jamc::srv::Func::Response > response)
 Callback function for the Play/Pause Service, used to toggle playback of the current track.
 
void play_direction_callback (const std::shared_ptr< jamc::srv::Func::Request > request, std::shared_ptr< jamc::srv::Func::Response > response)
 Callback function for the Play Direction Service, used to toggle the direction of playback.
 
void debug_service_callback (const std::shared_ptr< jamc::srv::Func::Request > request, std::shared_ptr< jamc::srv::Func::Response > response)
 Callback function for the debug service, used to test anything.
 
Control Loop

Functions related to the control loop of the controller

void control_loop ()
 The main control loop that runs when the control node starts.
 
double calculate_z (double xy)
 A helper method for calculating the target Z velocity (Scaled to meet a target height based on the X&Y magnitued)
 
std::optional< vector3calculate_velocity (int note)
 Velocity calculation for control loop. If the note is not visible, will travel in the parallel to the keyboard to find it.
 
std::optional< vector3play_note (double duration, double time)
 Plays a single note or presses a button, streams Z velocity for a hardcoded duration to push down on whatever the EE is above.
 

Private Attributes

Variables & Helpers

Variables used by the class

long CONTROL_TIME
 
Clock::time_point LAST_CONTROL_TIME_POINT
 
STATE state_
 
MidiProcessor connor
 
std::mutex key_positions_mutex_
 
geometry_msgs::msg::PoseArray key_positions_
 
std::mutex song_mutex_
 
std::vector< int > song_
 
std::vector< double > note_timings_
 
std::vector< double > note_durations_
 
bool play_ = false
 
double time_scale_ = 1.0
 
bool direction_ = true
 
int current_note_index_ = 0
 
bool song_loaded_ = false
 
std::mutex joint_mutex_
 
std::vector< double > latest_joint_state_
 
rclcpp::TimerBase::SharedPtr control_timer_
 
rclcpp::TimerBase::SharedPtr startup_timer_
 
bool startup_complete_ = false
 
Publishers

All Publishers that the Controller Class uses

rclcpp::Publisher< geometry_msgs::msg::TwistStamped >::SharedPtr twist_pub_
 
rclcpp::Publisher< control_msgs::msg::JointJog >::SharedPtr joint_traj_streaming_pub_
 
Subscribers

All Subscribers that the Controller Class uses

rclcpp::Subscription< geometry_msgs::msg::Point >::SharedPtr debug_target_sub_
 
rclcpp::Subscription< geometry_msgs::msg::PoseArray >::SharedPtr key_positions_sub_
 
rclcpp::Subscription< sensor_msgs::msg::JointState >::SharedPtr joint_state_sub_
 
Services

Services that the Controller Class provides

rclcpp::Service< jamc::srv::Load >::SharedPtr load_service_
 
rclcpp::Service< jamc::srv::TimeScale >::SharedPtr time_service_
 
rclcpp::Service< jamc::srv::Func >::SharedPtr play_pause_service_
 
rclcpp::Service< jamc::srv::Func >::SharedPtr play_direction_service_
 
rclcpp::Service< jamc::srv::Func >::SharedPtr debug_service_
 

Constructor & Destructor Documentation

◆ Controller()

Control::Controller::Controller ( )

Standalone Class for Controlling a UR3e. Typically reads data from .mipi files for plaback on a piano. Exposes various services for control.

This class contains the following ROS2 I/O

  • Services
    • '-/MIPI/load' (jamc/srv/Load): Takes a string which should be the filepath to a .mipi file to be loaded, and an integer that is the index of the instrument to play
    • '-/MIPI/time_scale' (jamc/srv/TimeScale): Take a float between 0 and 1 used to scale the speed of playback
    • '-/MIPI/play_pause' (jamc/srv/Func): Takes an empty, this is a trigger service used to play and pause the playback
    • '-/MIPI/direction' (jamc/srv/Func): Takes an empty, this is a trigger service used to toggle the direction of playback
Here is the call graph for this function:

◆ ~Controller()

Control::Controller::~Controller ( )

Standard Destructor for Controller Class.

Member Function Documentation

◆ activeTrackDebug()

int Control::Controller::activeTrackDebug ( vector3  target,
bool  x = false,
bool  y = false,
bool  z = false 
)
private

A method for enabling "activeTrack" mode, allowing for live visual servoing following a topic.

Parameters
targetA vector3 struct that is the target
xA bool to enable motion in the X plane
yA bool to enable motion in the Y plane
zA bool to enable motion in the Z plane

◆ calculate_velocity()

std::optional< vector3 > Control::Controller::calculate_velocity ( int  note)
private

Velocity calculation for control loop. If the note is not visible, will travel in the parallel to the keyboard to find it.

Parameters
noteThe MIDI note value for the current note being played

◆ calculate_z()

double Control::Controller::calculate_z ( double  xy)
private

A helper method for calculating the target Z velocity (Scaled to meet a target height based on the X&Y magnitued)

Parameters
xyThe magnitude of the vector in the x and y direction

◆ control_loop()

void Control::Controller::control_loop ( )
private

The main control loop that runs when the control node starts.

Here is the caller graph for this function:

◆ debug_service_callback()

void Control::Controller::debug_service_callback ( const std::shared_ptr< jamc::srv::Func::Request >  request,
std::shared_ptr< jamc::srv::Func::Response >  response 
)
private

Callback function for the debug service, used to test anything.

Parameters
requestThe request from the service call, empty for this trigger service
responseThe response for the service call, containing a message
Here is the caller graph for this function:

◆ debug_target_callback()

void Control::Controller::debug_target_callback ( const geometry_msgs::msg::Point::SharedPtr  msg)
private

Callback function for catching the debug subscriber, used to activate activeTrack.

Parameters
msgInput from the topic subscription
Here is the caller graph for this function:

◆ joint_state_callback()

void Control::Controller::joint_state_callback ( const sensor_msgs::msg::JointState::SharedPtr  msg)
private

Subscriber Callback that obtains the joint state of the robot.

Parameters
msgJointState object that contains the robots joint state
Here is the caller graph for this function:

◆ key_positions_callback()

void Control::Controller::key_positions_callback ( const geometry_msgs::msg::PoseArray::SharedPtr  msg)
private

Subscriber Callback that obtains the key positions from the.

Parameters
msgPoseArray containing the positions of the keys
Here is the caller graph for this function:

◆ load_callback()

void Control::Controller::load_callback ( const std::shared_ptr< jamc::srv::Load::Request >  request,
std::shared_ptr< jamc::srv::Load::Response >  response 
)
private

Callback function for the Load Service, used to load .mipi files and select which instrument channel.

Parameters
requestThe request from the service call, containing the filepath and instrument index
responseThe response for the service call, containing a message
Here is the caller graph for this function:

◆ play_direction_callback()

void Control::Controller::play_direction_callback ( const std::shared_ptr< jamc::srv::Func::Request >  request,
std::shared_ptr< jamc::srv::Func::Response >  response 
)
private

Callback function for the Play Direction Service, used to toggle the direction of playback.

Parameters
requestThe request from the service call, empty for this trigger service
responseThe response for the service call, containing a message
Here is the caller graph for this function:

◆ play_note()

std::optional< vector3 > Control::Controller::play_note ( double  duration,
double  time 
)
private

Plays a single note or presses a button, streams Z velocity for a hardcoded duration to push down on whatever the EE is above.

Parameters
durationThe time to hold the note for
timeThe current time into the note

◆ play_pause_callback()

void Control::Controller::play_pause_callback ( const std::shared_ptr< jamc::srv::Func::Request >  request,
std::shared_ptr< jamc::srv::Func::Response >  response 
)
private

Callback function for the Play/Pause Service, used to toggle playback of the current track.

Parameters
requestThe request from the service call, empty for this trigger service
responseThe response for the service call, containing a message
Here is the caller graph for this function:

◆ sendJointJog() [1/2]

void Control::Controller::sendJointJog ( double  shoulder_lift,
double  elbow,
double  wrist_1,
double  wrist_2,
double  wrist_3,
double  shoulder_pan 
)
private

A wrapper for sending joint jog commands for direct joint velocity control.

Parameters
shoulder_liftVelocity for the shoulder lift joint
elbowVelocity for the elbow joint
wrist_1Velocity for the wrist 1 joint
wrist_2Velocity for the wrist 2 joint
wrist_3Velocity for the wrist 3 joint
shoulder_panVelocity for the shoulder pan joint

◆ sendJointJog() [2/2]

void Control::Controller::sendJointJog ( std::vector< double >  vel)
private

A secondary wrapper for the sending Joint Jog commands that takes a vector instead of individual velocities.

Parameters
velA vector of doubles containing the joint velocities

◆ sendStop()

void Control::Controller::sendStop ( )
private

A simple helper method for immediately sending stop to the UR3e.

◆ sendTwistMsg()

void Control::Controller::sendTwistMsg ( double  x,
double  y,
double  z,
double  angular_x = 0.0,
double  angular_y = 0.0,
double  angular_z = 0.0 
)
private

A convenience method that neatly packs up a twist messge and publishes it to the UR_Driver.

Parameters
xA double for translational velocity of the End Effector in the X axis
yA double for translational velocity of the End Effector in the Y axis
zA double for translational velocity of the End Effector in the Z axis
angular_xA double for rotational velocity of the End Effector in the X axis (Optional, Defaults to 0.0)
angular_yA double for rotational velocity of the End Effector in the Y axis (Optional, Defaults to 0.0)
angular_zA double for rotational velocity of the End Effector in the Z axis (Optional, Defaults to 0.0)

◆ sendVector()

void Control::Controller::sendVector ( const vector3 vec)
private

The public method for sending translational End Effector vector commands to the UR3e.

Parameters
vecTakes a vector3 struct (included in this class, or declared using {x, y, z})

◆ startup()

void Control::Controller::startup ( )
private

The startup sequence that moves the robot into the starting position for playing.

Here is the caller graph for this function:

◆ time_scale_callback()

void Control::Controller::time_scale_callback ( const std::shared_ptr< jamc::srv::TimeScale::Request >  request,
std::shared_ptr< jamc::srv::TimeScale::Response >  response 
)
private

Callback function for the TimeScale Service, used to set the time scaling factor for playback.

Parameters
requestThe request from the service call, containing the time scale factor
responseThe response for the service call, containing a message
Here is the caller graph for this function:

Member Data Documentation

◆ connor

MidiProcessor Control::Controller::connor
private

◆ CONTROL_TIME

long Control::Controller::CONTROL_TIME
private

◆ control_timer_

rclcpp::TimerBase::SharedPtr Control::Controller::control_timer_
private

◆ current_note_index_

int Control::Controller::current_note_index_ = 0
private

◆ debug_service_

rclcpp::Service<jamc::srv::Func>::SharedPtr Control::Controller::debug_service_
private

◆ debug_target_sub_

rclcpp::Subscription<geometry_msgs::msg::Point>::SharedPtr Control::Controller::debug_target_sub_
private

◆ direction_

bool Control::Controller::direction_ = true
private

◆ joint_mutex_

std::mutex Control::Controller::joint_mutex_
private

◆ joint_state_sub_

rclcpp::Subscription<sensor_msgs::msg::JointState>::SharedPtr Control::Controller::joint_state_sub_
private

◆ joint_traj_streaming_pub_

rclcpp::Publisher<control_msgs::msg::JointJog>::SharedPtr Control::Controller::joint_traj_streaming_pub_
private

◆ key_positions_

geometry_msgs::msg::PoseArray Control::Controller::key_positions_
private

◆ key_positions_mutex_

std::mutex Control::Controller::key_positions_mutex_
private

◆ key_positions_sub_

rclcpp::Subscription<geometry_msgs::msg::PoseArray>::SharedPtr Control::Controller::key_positions_sub_
private

◆ LAST_CONTROL_TIME_POINT

Clock::time_point Control::Controller::LAST_CONTROL_TIME_POINT
private

◆ latest_joint_state_

std::vector<double> Control::Controller::latest_joint_state_
private

◆ load_service_

rclcpp::Service<jamc::srv::Load>::SharedPtr Control::Controller::load_service_
private

◆ note_durations_

std::vector<double> Control::Controller::note_durations_
private

◆ note_timings_

std::vector<double> Control::Controller::note_timings_
private

◆ play_

bool Control::Controller::play_ = false
private

◆ play_direction_service_

rclcpp::Service<jamc::srv::Func>::SharedPtr Control::Controller::play_direction_service_
private

◆ play_pause_service_

rclcpp::Service<jamc::srv::Func>::SharedPtr Control::Controller::play_pause_service_
private

◆ song_

std::vector<int> Control::Controller::song_
private

◆ song_loaded_

bool Control::Controller::song_loaded_ = false
private

◆ song_mutex_

std::mutex Control::Controller::song_mutex_
private

◆ startup_complete_

bool Control::Controller::startup_complete_ = false
private

◆ startup_timer_

rclcpp::TimerBase::SharedPtr Control::Controller::startup_timer_
private

◆ state_

STATE Control::Controller::state_
private

◆ time_scale_

double Control::Controller::time_scale_ = 1.0
private

◆ time_service_

rclcpp::Service<jamc::srv::TimeScale>::SharedPtr Control::Controller::time_service_
private

◆ twist_pub_

rclcpp::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr Control::Controller::twist_pub_
private

The documentation for this class was generated from the following files: