Cheetah Software  1.0
rt_interface_lcm.h File Reference
#include <lcm/lcm-cpp.hpp>
+ Include dependency graph for rt_interface_lcm.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Handler
 

Functions

void sbus_packet_complete ()
 Function which handles the completion of an SBUS Packet and overrides the LCM control settings as desired. More...
 
void get_main_control_settings (void *settings)
 
int get_iterations_since_last_lcm ()
 Gets the iterations since the last lcm. More...
 
void get_rc_channels (void *settings)
 
void init_interface_lcm (lcm::LCM *main_lcm)
 Initializer for all handlers related to the interface LCM streams. More...
 
void control_iteration_lcm ()
 Increments the number of control iterations since the last LCM packet. More...
 
void * v_memcpy (void *dest, volatile void *src, size_t n)
 

Function Documentation

void control_iteration_lcm ( )

Increments the number of control iterations since the last LCM packet.

Definition at line 18 of file rt_interface_lcm.cpp.

References iterations_since_last_lcm.

int iterations_since_last_lcm
int get_iterations_since_last_lcm ( )

Gets the iterations since the last lcm.

Returns
The iterations since last lcm.

Definition at line 25 of file rt_interface_lcm.cpp.

References iterations_since_last_lcm.

25 { return iterations_since_last_lcm; }
int iterations_since_last_lcm
void get_main_control_settings ( void *  settings)

Definition at line 62 of file rt_interface_lcm.cpp.

References lcm_get_set_mutex, main_control_settings, and v_memcpy().

62  {
63  pthread_mutex_lock(&lcm_get_set_mutex);
65  pthread_mutex_unlock(&lcm_get_set_mutex);
66 }
void * v_memcpy(void *dest, volatile void *src, size_t n)
static pthread_mutex_t lcm_get_set_mutex
gui_main_control_settings_t main_control_settings

+ Here is the call graph for this function:

void get_rc_channels ( void *  settings)

Definition at line 68 of file rt_interface_lcm.cpp.

References lcm_get_set_mutex, rc_channels, and v_memcpy().

68  {
69  pthread_mutex_lock(&lcm_get_set_mutex);
70  v_memcpy(settings, &rc_channels, sizeof(rc_channels));
71  pthread_mutex_unlock(&lcm_get_set_mutex);
72 }
void * v_memcpy(void *dest, volatile void *src, size_t n)
rc_channels_t rc_channels
static pthread_mutex_t lcm_get_set_mutex

+ Here is the call graph for this function:

void init_interface_lcm ( lcm::LCM *  main_lcm)

Initializer for all handlers related to the interface LCM streams.

Parameters
main_lcmA pointer to the main lcm object used in the lcm thread

Definition at line 172 of file rt_interface_lcm.cpp.

References g_lcm, main_control_settings, Handler::main_control_settings_handler(), and Handler::rc_channels_handler().

172  {
173  printf("[RT Interface LCM] Initializing...\n");
174  g_lcm = main_lcm;
175 
176  Handler handlerObj;
177 
178  g_lcm->subscribe("INTERFACE_gui_main_control_settings",
180  g_lcm->subscribe("INTERFACE_rc_channels", &Handler::rc_channels_handler,
181  &handlerObj);
182 
183  main_control_settings.enable = 1;
184 
185  printf("[RT Interface LCM] Done\n");
186 
187  // printf("Initial PFOOT SETTINGS %lf\n",
188  // state_estimator_settings.process_noise_pfoot);
189 }
void main_control_settings_handler(const lcm::ReceiveBuffer *rbuf, const std::string &channel, const gui_main_control_settings_t *msg)
Handler for main control settings from MATLAB interface. Never call this yourself, leave it to LCM.
static lcm::LCM * g_lcm
void rc_channels_handler(const lcm::ReceiveBuffer *rbuf, const std::string &channel, const rc_channels_t *msg)
gui_main_control_settings_t main_control_settings

+ Here is the call graph for this function:

void sbus_packet_complete ( )

Function which handles the completion of an SBUS Packet and overrides the LCM control settings as desired.

Definition at line 78 of file rt_interface_lcm.cpp.

References f(), lcm_get_set_mutex, main_control_settings, and read_sbus_channel().

78  {
79  pthread_mutex_lock(&lcm_get_set_mutex);
80 
81  int ch1 = read_sbus_channel(0);
82  int ch2 = read_sbus_channel(1);
83  int ch3 = read_sbus_channel(2);
84  int ch4 = read_sbus_channel(3);
85  int ch7 = read_sbus_channel(6);
86  int ch9 = read_sbus_channel(8);
87  int ch10 = read_sbus_channel(9);
88  int ch11 = read_sbus_channel(10);
89  int ch13 = read_sbus_channel(12);
90 
91  // velocity scales between 1.0 and 3.0
92  float v_scale = 2.0f * (((float)(ch7 - 172)) / 1811.0f) + 1.0f;
93  // Ignore commands if switched
94  if (ch11 != 1811) {
95  // oh shit switch
96  if (ch10 == 172) {
97  main_control_settings.mode = 0;
98  } else if (ch10 == 992) {
99  main_control_settings.mode = 12;
100  } else if (ch10 == 1811) {
101  main_control_settings.mode = 11;
102  }
103 
104  // Use the joysticks for velocity and yaw control in locomotion gaits
105  if (main_control_settings.mode == 11) {
106  // Analog channels return a value between ~200 and 1800, with sticks
107  // centered at 1000
108 
109  if (ch9 == 1811) {
110  main_control_settings.variable[0] = 4;
111  } // Stand
112  else if (ch9 == 992) {
113  main_control_settings.variable[0] = 0;
114  } // Trot
115  else if ((ch9 == 172) && (ch13 == 1811)) {
116  main_control_settings.variable[0] = 5;
117  } // Trot run
118  else if ((ch9 == 172) && (ch13 == 992)) {
119  main_control_settings.variable[0] = 2;
120  } // Pronk
121  else if ((ch9 == 172) && (ch13 == 172)) {
122  main_control_settings.variable[0] = 1;
123  } // Bound
124 
125  // If using the stand gait, control orientations
126  if (main_control_settings.variable[0] == 4) {
127  main_control_settings.rpy_des[0] = ((float)ch4 - 1000) * .0003f;
128  main_control_settings.rpy_des[1] = ((float)ch3 - 1000) * .0005f;
129  main_control_settings.rpy_des[2] = ((float)ch2 - 1000) * .001f;
130 
131  main_control_settings.p_des[0] = 0;
132  main_control_settings.p_des[1] = 0;
133  main_control_settings.p_des[2] = 0.21 + ((float)ch1 - 1000) * .0001f;
134  }
135  // For all other gaits, control the velocities
136  else {
137  main_control_settings.v_des[0] = v_scale * ((float)ch1 - 1000) * .002f;
138  main_control_settings.v_des[1] =
139  -v_scale * ((float)ch4 - 1000) * .0005f;
140  main_control_settings.v_des[2] = 0;
141  main_control_settings.p_des[2] = 0.21;
142 
143  main_control_settings.omega_des[0] = 0;
144  main_control_settings.omega_des[1] = 0;
145  main_control_settings.omega_des[2] =
146  -v_scale * ((float)ch2 - 1000) * .003f;
147  }
148  }
149  // For standing modes (mpc or balance qp) control orientations
150  else if (main_control_settings.mode == 10 ||
151  main_control_settings.mode == 3) {
152  main_control_settings.rpy_des[0] = ((float)ch4 - 1000) * .0003f;
153  main_control_settings.rpy_des[1] = ((float)ch3 - 1000) * .0005f;
154  main_control_settings.rpy_des[2] = ((float)ch2 - 1000) * .001f;
155 
156  main_control_settings.p_des[0] = 0;
157  main_control_settings.p_des[1] = 0;
158  main_control_settings.p_des[2] = 0.21 + ((float)ch1 - 1000) * .0001f;
159  }
160  }
161  // Use the joysticks for orientation and height control in standing mode
162 
163  pthread_mutex_unlock(&lcm_get_set_mutex);
164  // printf("[RT Interface LCM] Got SBUS Packet\n");
165 }
int read_sbus_channel(int channel)
Definition: rt_sbus.cpp:101
static pthread_mutex_t lcm_get_set_mutex
gui_main_control_settings_t main_control_settings
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void* v_memcpy ( void *  dest,
volatile void *  src,
size_t  n 
)

Definition at line 191 of file rt_interface_lcm.cpp.

191  {
192  void *src_2 = (void *)src;
193  return memcpy(dest, src_2, n);
194 }

+ Here is the caller graph for this function: