real_robot.cpp
Go to the documentation of this file.
2 
3 
4 RealRobot::Wheel::Wheel(const std::string &wheel_name, int counts_per_rev)
5 {
6  name = wheel_name;
7  rads_per_count = (2*M_PI)/counts_per_rev;
8 }
9 
10 
12 {
13  return enc * rads_per_count;
14 }
15 
16 
18  : arduino_(cfg.device, cfg.baud_rate, cfg.timeout),
19  l_wheel_(cfg.left_wheel_name, cfg.enc_counts_per_rev),
20  r_wheel_(cfg.right_wheel_name, cfg.enc_counts_per_rev)
21 {
22 
23  loop_rate_ = cfg.loop_rate;
24 
26  // arduino.setPidValues(9,7,0,100);
27  // arduino.setPidValues(14,7,0,100);
28  arduino_.setPidValues(30, 20, 0, 100);
29 
30  // connect and register the joint state interface
32  jnt_state_interface_.registerHandle(state_handle_a);
33 
35  jnt_state_interface_.registerHandle(state_handle_b);
36 
38 
39  // connect and register the joint position interface
41  jnt_vel_interface_.registerHandle(vel_handle_a);
42 
44  jnt_vel_interface_.registerHandle(vel_handle_b);
45 
47 }
48 
50 {
51 
52  ros::Time new_time = ros::Time::now();
53  period_ = new_time - time_;
54  time_ = new_time;
55 
56  if (!arduino_.connected())
57  {
58  return;
59  }
60 
62 
63  double pos_prev = l_wheel_.pos;
65  l_wheel_.vel = (l_wheel_.pos - pos_prev) / period_.toSec();
66 
67  pos_prev = r_wheel_.pos;
69  r_wheel_.vel = (r_wheel_.pos - pos_prev) / period_.toSec();
70 }
71 
73 {
74  if (!arduino_.connected())
75  {
76  return;
77  }
78 
80 }
std::string name
Definition: real_robot.h:32
float loop_rate_
Definition: real_robot.h:68
void setMotorValues(int val_1, int val_2)
ros::Time time_
Definition: real_robot.h:66
ArduinoComms arduino_
Definition: real_robot.h:61
ros::Duration period_
Definition: real_robot.h:67
Wheel r_wheel_
Definition: real_robot.h:64
void read()
Definition: real_robot.cpp:49
hardware_interface::JointStateInterface jnt_state_interface_
Definition: real_robot.h:59
RealRobot(const Config &cfg)
Definition: real_robot.cpp:17
bool connected() const
Definition: arduino_comms.h:22
void readEncoderValues(int &val_1, int &val_2)
Wheel l_wheel_
Definition: real_robot.h:63
Wheel(const std::string &wheel_name, int counts_per_rev)
Definition: real_robot.cpp:4
hardware_interface::VelocityJointInterface jnt_vel_interface_
Definition: real_robot.h:60
void registerHandle(const JointStateHandle &handle)
double calcEncAngle()
Definition: real_robot.cpp:11
JointStateHandle getHandle(const std::string &name)
static Time now()
void sendEmptyMsg()
void write()
Definition: real_robot.cpp:72
double rads_per_count
Definition: real_robot.h:39
void setPidValues(float k_p, float k_d, float k_i, float k_o)


diffdrive_arduino
Author(s): Josh Newans
autogenerated on Mon Feb 28 2022 22:13:39