robotcar.h
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef ROBOTCAR_H
#define ROBOTCAR_H
#include "periph/pwm.h"
#include "periph/gpio.h"
#include "xtimer.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WHEEL_DIAM 65 //mm
#define STEP_COUNT 20
typedef struct {
pwm_t device; /**< the PWM device driving the robot */
int channel; /**< the channel the robot is connected to */
gpio_t in1;
gpio_t in2;
gpio_t encoder;
gpio_t stby;
int counter;
int id;
} robot_t;
//define data type to send
typedef union
{
uint32_t msg;
struct
{
uint8_t cmd;
uint8_t step;
uint16_t speed;
};
}word;
int robot_init(robot_t *dev, pwm_t pwm, int pwm_channel, gpio_t in1, gpio_t in2, gpio_t stby, gpio_t encoder,int id);
void robot_drive( robot_t *dev, uint16_t speed, int direction);
void robot_fw(robot_t *dev, uint16_t speed);
void robot_rev(robot_t *dev, uint16_t speed);
void robot_stop(robot_t *dev1, robot_t *dev2);
void robot_move_forward(robot_t *dev1, robot_t *dev2, uint16_t speed,int steps);
void robot_move_reverse( robot_t *dev1, robot_t *dev2, uint16_t speed,int steps);
void robot_spin_left( robot_t *dev1, robot_t *dev2, uint16_t speed,int steps);
void robot_spin_right( robot_t *dev1, robot_t *dev2, uint16_t speed,int steps);
void robot_step_counter( robot_t *dev);
int cm_to_steps(uint8_t cm);
#ifdef __cplusplus
}
#endif
#endif /* ROBOTCAR_H */
/** @} */