Cheetah Software  1.0
rt_spi.h
Go to the documentation of this file.
1 #ifndef _rt_spi
2 #define _rt_spi
3 
4 #include <fcntl.h> //Needed for SPI port
5 #include <sys/ioctl.h> //Needed for SPI port
6 
7 // incredibly obscure bug in SPI_IOC_MESSAGE macro is fixed by this
8 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
9 extern "C" {
10 #endif
11 
12 #include <linux/spi/spidev.h>
13 
14 #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
15 }
16 #endif
17 
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h> //Needed for SPI port
23 #include <spi_command_t.hpp>
24 #include <spi_data_t.hpp>
25 #include <spi_torque_t.hpp>
26 
27 #define K_EXPECTED_COMMAND_SIZE 256
28 #define K_WORDS_PER_MESSAGE 66
29 #define K_EXPECTED_DATA_SIZE 116
30 #define K_KNEE_OFFSET_POS 4.35f
31 
32 #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
33 #define BYTE_TO_BINARY(byte) \
34  (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), \
35  (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), \
36  (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), \
37  (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')
38 
39 void init_spi();
40 
41 void spi_send_receive(spi_command_t* command, spi_data_t* data);
42 void spi_driver_run();
43 
44 spi_data_t* get_spi_data();
45 spi_command_t* get_spi_command();
46 
47 typedef struct {
48  float q_des_abad[2];
49  float q_des_hip[2];
50  float q_des_knee[2];
51  float qd_des_abad[2];
52  float qd_des_hip[2];
53  float qd_des_knee[2];
54  float kp_abad[2];
55  float kp_hip[2];
56  float kp_knee[2];
57  float kd_abad[2];
58  float kd_hip[2];
59  float kd_knee[2];
60  float tau_abad_ff[2];
61  float tau_hip_ff[2];
62  float tau_knee_ff[2];
63  int32_t flags[2];
64  int32_t checksum;
65 
66 } spine_cmd_t;
67 
68 typedef struct {
69  float q_abad[2];
70  float q_hip[2];
71  float q_knee[2];
72  float qd_abad[2];
73  float qd_hip[2];
74  float qd_knee[2];
75  int32_t flags[2];
76  int32_t checksum;
77 
78 } spine_data_t;
79 
80 #endif
int32_t checksum
Definition: rt_spi.h:64
void spi_driver_run()
Definition: rt_spi.cpp:319
void init_spi()
Definition: rt_spi.cpp:110
int32_t checksum
Definition: rt_spi.h:76
spi_data_t * get_spi_data()
Definition: rt_spi.cpp:337
void spi_send_receive(spi_command_t *command, spi_data_t *data)
Definition: rt_spi.cpp:260
spi_command_t * get_spi_command()
Definition: rt_spi.cpp:332