5#include "jamc/srv/load.hpp"
6#include "jamc/srv/func.hpp"
7#include "jamc/srv/time_scale.hpp"
12#include "rclcpp/rclcpp.hpp"
13#include <geometry_msgs/msg/twist_stamped.hpp>
14#include <geometry_msgs/msg/point.hpp>
18#include <geometry_msgs/msg/pose_array.hpp>
19#include <sensor_msgs/msg/joint_state.hpp>
20#include <control_msgs/msg/joint_jog.hpp>
22using Clock = std::chrono::steady_clock;
94 void sendTwistMsg(
double x,
double y,
double z,
double angular_x = 0.0,
double angular_y = 0.0,
double angular_z = 0.0);
95 void sendJointJog(
double shoulder_lift,
double elbow,
double wrist_1,
double wrist_2,
double wrist_3,
double shoulder_pan);
117 rclcpp::Publisher<geometry_msgs::msg::TwistStamped>::SharedPtr
twist_pub_;
162 void load_callback(
const std::shared_ptr<jamc::srv::Load::Request> request, std::shared_ptr<jamc::srv::Load::Response> response);
163 void time_scale_callback(
const std::shared_ptr<jamc::srv::TimeScale::Request> request, std::shared_ptr<jamc::srv::TimeScale::Response> response);
164 void play_pause_callback(
const std::shared_ptr<jamc::srv::Func::Request> request, std::shared_ptr<jamc::srv::Func::Response> response);
165 void play_direction_callback(
const std::shared_ptr<jamc::srv::Func::Request> request, std::shared_ptr<jamc::srv::Func::Response> response);
166 void debug_service_callback(
const std::shared_ptr<jamc::srv::Func::Request> request, std::shared_ptr<jamc::srv::Func::Response> response);
178 std::optional<vector3>
play_note(
double duration,
double time);
Definition controller.h:50
rclcpp::Service< jamc::srv::Load >::SharedPtr load_service_
Definition controller.h:149
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.
Definition controller.cpp:242
void sendVector(const vector3 &vec)
The public method for sending translational End Effector vector commands to the UR3e.
Definition controller.cpp:75
std::optional< vector3 > play_note(double duration, double time)
Plays a single note or presses a button, streams Z velocity for a hardcoded duration to push down on ...
Definition controller.cpp:377
rclcpp::Subscription< geometry_msgs::msg::Point >::SharedPtr debug_target_sub_
Definition controller.h:127
rclcpp::Subscription< sensor_msgs::msg::JointState >::SharedPtr joint_state_sub_
Definition controller.h:129
Clock::time_point LAST_CONTROL_TIME_POINT
Definition controller.h:62
std::vector< double > latest_joint_state_
Definition controller.h:80
Controller()
Standalone Class for Controlling a UR3e. Typically reads data from .mipi files for plaback on a piano...
Definition controller.cpp:15
void joint_state_callback(const sensor_msgs::msg::JointState::SharedPtr msg)
Subscriber Callback that obtains the joint state of the robot.
Definition controller.cpp:419
rclcpp::Service< jamc::srv::Func >::SharedPtr play_pause_service_
Definition controller.h:151
double calculate_z(double xy)
A helper method for calculating the target Z velocity (Scaled to meet a target height based on the X&...
Definition controller.cpp:388
bool startup_complete_
Definition controller.h:85
void control_loop()
The main control loop that runs when the control node starts.
Definition controller.cpp:281
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.
Definition controller.cpp:206
rclcpp::Publisher< control_msgs::msg::JointJog >::SharedPtr joint_traj_streaming_pub_
Definition controller.h:118
rclcpp::TimerBase::SharedPtr control_timer_
Definition controller.h:82
void startup()
The startup sequence that moves the robot into the starting position for playing.
Definition controller.cpp:428
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.
Definition controller.cpp:269
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.
Definition controller.cpp:479
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.
Definition controller.cpp:95
rclcpp::TimerBase::SharedPtr startup_timer_
Definition controller.h:83
bool song_loaded_
Definition controller.h:77
std::vector< double > note_durations_
Definition controller.h:71
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.
Definition controller.cpp:52
void key_positions_callback(const geometry_msgs::msg::PoseArray::SharedPtr msg)
Subscriber Callback that obtains the key positions from the.
Definition controller.cpp:399
rclcpp::Subscription< geometry_msgs::msg::PoseArray >::SharedPtr key_positions_sub_
Definition controller.h:128
rclcpp::Service< jamc::srv::Func >::SharedPtr play_direction_service_
Definition controller.h:152
rclcpp::Service< jamc::srv::TimeScale >::SharedPtr time_service_
Definition controller.h:150
std::mutex key_positions_mutex_
Definition controller.h:65
long CONTROL_TIME
Definition controller.h:61
std::vector< double > note_timings_
Definition controller.h:70
bool play_
Definition controller.h:73
std::mutex joint_mutex_
Definition controller.h:79
std::optional< vector3 > calculate_velocity(int note)
Velocity calculation for control loop. If the note is not visible, will travel in the parallel to the...
Definition controller.cpp:150
int current_note_index_
Definition controller.h:76
geometry_msgs::msg::PoseArray key_positions_
Definition controller.h:66
bool direction_
Definition controller.h:75
std::mutex song_mutex_
Definition controller.h:68
~Controller()
Standard Destructor for Controller Class.
Definition controller.cpp:38
STATE state_
Definition controller.h:63
rclcpp::Service< jamc::srv::Func >::SharedPtr debug_service_
Definition controller.h:153
std::vector< int > song_
Definition controller.h:69
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.
Definition controller.cpp:550
rclcpp::Publisher< geometry_msgs::msg::TwistStamped >::SharedPtr twist_pub_
Definition controller.h:117
MidiProcessor connor
Definition controller.h:64
double time_scale_
Definition controller.h:74
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.
Definition controller.cpp:255
void debug_target_callback(const geometry_msgs::msg::Point::SharedPtr msg)
Callback function for catching the debug subscriber, used to activate activeTrack.
Definition controller.cpp:108
void sendStop()
A simple helper method for immediately sending stop to the UR3e.
Definition controller.cpp:83
Standalone Class for processing midi files and saving/loading mipi files. Contains various getters to...
Definition midi_processor.h:54
std::chrono::steady_clock Clock
Definition controller.h:22
Definition controller.h:25
STATE
An enum for representing the state of the controller, used to determine behavior in the control loop ...
Definition controller.h:43
A struct for representing 3D vectors, used for velocity commands and target positions.
Definition controller.h:30
double z
Definition controller.h:33
double x
Definition controller.h:31
double y
Definition controller.h:32