cmd_server.hpp
Go to the documentation of this file.
1 
9 #ifndef CMD_SERVER_HPP
10 #define CMD_SERVER_HPP
11 
12 // System
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 
18 // Marty
19 #include "marty_msgs/Command.h"
20 #include "marty_msgs/ServoMsg.h"
21 #include "marty_msgs/ServoMsgArray.h"
22 #include "ros_marty/marty_core.hpp"
23 #include "ros_marty/trajectory.hpp"
24 
25 // ROS
26 #include "std_msgs/Float32.h"
27 #include "geometry_msgs/Pose2D.h"
28 #include "marty_msgs/GPIOs.h"
29 #include "marty_msgs/Accelerometer.h"
30 #include "marty_msgs/MotorCurrents.h"
31 
32 #define PORT 1569
33 
34 // This wait time is required when a stop message is sent straight after
35 #define stop_wait 150 // Wait time between instantaneous servo commands
36 
40 enum Direction {
41  CMD_LEFT = 0,
45 };
46 
47 enum Axis {
48  AXES_X = 0,
51 };
52 
53 enum Joint {
54  J_HIP = 0,
60 };
61 
62 enum Commands {
63  CMD_HELLO = 0,
81 };
82 
83 enum Sensors {
84  GET_GPIO = 0,
89 };
90 
91 class CmdServer {
92  protected:
93  ros::NodeHandle nh_;
94  void loadParams();
95  void init();
96  void rosSetup();
97 
98  private:
99  // Methods
100  void runCommand(vector<int> data);
101  void runSockCommand(vector<int8_t> data);
102 
103  void arms(int r_angle = 0, int l_angle = 0);
104  void celebrate(int move_time = 4000);
105  void dance(int robot_id);
106  void demo();
107  void eyes(int amount = 0, int amount2 = 0);
108  void getData(int sensor, int id);
109  void hello();
110  void kick(int side = CMD_LEFT, int move_time = 3000);
111  void lean(int dir, int amount = 100, int move_time = 2000);
112  void liftLeg(int leg, int amount = 100, int move_time = 2000);
113  void lowerLeg(int move_time = 1000);
114  void moveJoint(int side, int joint, int amount, int move_time = 2000);
115  void sideStep(int side, int num_steps = 1, int move_time = 1000,
116  int step_length = 50);
117  void standStraight(int move_time = 1000);
118  void playSound(int freq = 440, int duration = 500);
119  void playSounds(std::vector<int> sounds);
120  void stopRobot();
121  void walk(int num_steps = 2, int turn = 0,
122  int move_time = 3000, int step_length = 50, int side = -1);
123 
124  void testLeg(int side, int duration);
125  void sitBack(int duration);
126  void swingArms(int r_arm, int l_arm, int duration = 2000, int cycles = 4);
127  void swingJoints(marty_msgs::ServoMsgArray, int duration = 2000,
128  int cycles = 4);
129 
130  void gpioCB(const marty_msgs::GPIOs& msg) {gpio_data_ = msg;}
131  void accelCB(const marty_msgs::Accelerometer& msg) {accel_data_ = msg;}
132  void battCB(const std_msgs::Float32& msg) {batt_data_ = msg;}
133  void currCB(const marty_msgs::MotorCurrents& msg) {curr_data_ = msg;}
134  void ballCB(const geometry_msgs::Pose2D& msg) {ball_pos_ = msg;}
135  bool cmd_service(marty_msgs::Command::Request& req,
136  marty_msgs::Command::Response& res);
137 
138  // Flags
139  bool busy_;
140  bool ros_cmd_;
143 
144  // Params
146 
147  // Variables
149  int sock_;
150  float interp_dt_;
151  std::vector<int> cmd_data_;
152  std::vector<std::vector<int> > cmd_queue_;
154  marty_msgs::GPIOs gpio_data_;
155  marty_msgs::Accelerometer accel_data_;
156  std_msgs::Float32 batt_data_;
157  marty_msgs::MotorCurrents curr_data_;
158  geometry_msgs::Pose2D ball_pos_;
159 
160  // ROS
161  ros::Subscriber gpio_sub_;
162  ros::Subscriber accel_sub_;
163  ros::Subscriber batt_sub_;
164  ros::Subscriber curr_sub_;
165  ros::Subscriber ball_sub_;
166  ros::ServiceServer cmd_srv_;
167 
168  public:
169  CmdServer(ros::NodeHandle& nh);
170  ~CmdServer();
171  void robotReady();
172  void setupServer();
173  void stopServer();
174  void waitForCmd();
175 };
176 
177 #endif /* CMD_SERVER_HPP */
void sideStep(int side, int num_steps=1, int move_time=1000, int step_length=50)
Definition: cmd_server.cpp:472
void arms(int r_angle=0, int l_angle=0)
Definition: cmd_server.cpp:307
void sitBack(int duration)
Definition: cmd_server.cpp:422
void stopRobot()
Definition: cmd_server.cpp:516
geometry_msgs::Pose2D ball_pos_
Definition: cmd_server.hpp:158
void demo()
Definition: cmd_server.cpp:312
ros::Subscriber curr_sub_
Definition: cmd_server.hpp:164
void moveJoint(int side, int joint, int amount, int move_time=2000)
Definition: cmd_server.cpp:194
void playSound(int freq=440, int duration=500)
void liftLeg(int leg, int amount=100, int move_time=2000)
Definition: cmd_server.cpp:261
void walk(int num_steps=2, int turn=0, int move_time=3000, int step_length=50, int side=-1)
Definition: cmd_server.cpp:126
void dance(int robot_id)
Definition: cmd_server.cpp:302
std::vector< int > cmd_data_
Definition: cmd_server.hpp:151
void waitForCmd()
Definition: cmd_server.cpp:602
void swingArms(int r_arm, int l_arm, int duration=2000, int cycles=4)
Definition: cmd_server.cpp:427
float interp_dt_
Definition: cmd_server.hpp:150
ros::ServiceServer cmd_srv_
Definition: cmd_server.hpp:166
void loadParams()
Definition: cmd_server.cpp:541
void runCommand(vector< int > data)
Runs commands received by the server.
Definition: cmd_server.cpp:48
void accelCB(const marty_msgs::Accelerometer &msg)
Definition: cmd_server.hpp:131
marty_msgs::MotorCurrents curr_data_
Definition: cmd_server.hpp:157
bool turn_spot_
Definition: cmd_server.hpp:142
void ballCB(const geometry_msgs::Pose2D &msg)
Definition: cmd_server.hpp:134
Marty Core header providing access to Marty methods.
CmdServer(ros::NodeHandle &nh)
Definition: cmd_server.cpp:530
Commands
Definition: cmd_server.hpp:62
bool ready_move_
Definition: cmd_server.hpp:145
ros::Subscriber batt_sub_
Definition: cmd_server.hpp:163
void celebrate(int move_time=4000)
Definition: cmd_server.cpp:250
void rosSetup()
Definition: cmd_server.cpp:560
ros::Subscriber gpio_sub_
Definition: cmd_server.hpp:161
marty_msgs::Accelerometer accel_data_
Definition: cmd_server.hpp:155
void eyes(int amount=0, int amount2=0)
Definition: cmd_server.cpp:167
ros::Subscriber ball_sub_
Definition: cmd_server.hpp:165
MartyCore * robot_
Definition: cmd_server.hpp:148
void hello()
Definition: cmd_server.cpp:113
void init()
Definition: cmd_server.cpp:551
Joint
Definition: cmd_server.hpp:53
void testLeg(int side, int duration)
Definition: cmd_server.cpp:411
std_msgs::Float32 batt_data_
Definition: cmd_server.hpp:156
void runSockCommand(vector< int8_t > data)
Definition: cmd_server.cpp:98
bool cmd_service(marty_msgs::Command::Request &req, marty_msgs::Command::Response &res)
Definition: cmd_server.cpp:569
bool ros_cmd_
Definition: cmd_server.hpp:140
Axis
Definition: cmd_server.hpp:47
void setupServer()
Definition: cmd_server.cpp:576
Sensors
Definition: cmd_server.hpp:83
void stopServer()
Definition: cmd_server.cpp:598
void getData(int sensor, int id)
Definition: cmd_server.cpp:171
std::vector< std::vector< int > > cmd_queue_
Definition: cmd_server.hpp:152
void kick(int side=CMD_LEFT, int move_time=3000)
Definition: cmd_server.cpp:154
void swingJoints(marty_msgs::ServoMsgArray, int duration=2000, int cycles=4)
Definition: cmd_server.cpp:448
ros::NodeHandle nh_
Definition: cmd_server.hpp:93
void currCB(const marty_msgs::MotorCurrents &msg)
Definition: cmd_server.hpp:133
void playSounds(std::vector< int > sounds)
Definition: cmd_server.cpp:499
bool resp_request_
Definition: cmd_server.hpp:141
void standStraight(int move_time=1000)
Definition: cmd_server.cpp:486
void battCB(const std_msgs::Float32 &msg)
Definition: cmd_server.hpp:132
marty_msgs::GPIOs gpio_data_
Definition: cmd_server.hpp:154
float val_request_
Definition: cmd_server.hpp:153
Direction
Add new commands here for the server to receive.
Definition: cmd_server.hpp:40
void gpioCB(const marty_msgs::GPIOs &msg)
Definition: cmd_server.hpp:130
void lean(int dir, int amount=100, int move_time=2000)
Definition: cmd_server.cpp:238
void robotReady()
Robot motion executed when cmdServer is ready.
Definition: cmd_server.cpp:16
ros::Subscriber accel_sub_
Definition: cmd_server.hpp:162
void lowerLeg(int move_time=1000)
Definition: cmd_server.cpp:279
float freq
Definition: serial_read.py:22


ros_marty
Author(s): Alejandro Bordallo
autogenerated on Fri Jul 21 2017 14:51:45