robotcar.h 1.37 KB
#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 */
/** @} */