Merge branch 'feature/improved_drive' into 'develop'
acceleration behaviour reproduced See merge request !13
This commit is contained in:
commit
ed8119b716
@ -21,6 +21,8 @@ struct drive_ctrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct drive_ctrl_object {
|
struct drive_ctrl_object {
|
||||||
|
unsigned int target_speed;
|
||||||
|
unsigned int turn_speed;
|
||||||
unsigned int current_speed;
|
unsigned int current_speed;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,7 +34,9 @@ static struct drive_ctrl drive_ctrl = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static struct drive_ctrl_object drive_ctrl_object = {
|
static struct drive_ctrl_object drive_ctrl_object = {
|
||||||
.current_speed = 50, /* % */
|
.target_speed = 80, /* % */
|
||||||
|
.turn_speed = 40,
|
||||||
|
.current_speed = 0, /* % */
|
||||||
};
|
};
|
||||||
|
|
||||||
int drive_ctrl_init(void)
|
int drive_ctrl_init(void)
|
||||||
@ -112,14 +116,38 @@ int drive_ctrl_set_speed_right(int speed_percent)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drive_ctrl_set_speed_value(int speed_percent)
|
int drive_ctrl_set_target_speed_value(int speed_percent)
|
||||||
|
{
|
||||||
|
drive_ctrl_object.target_speed = speed_percent;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_get_target_speed_value(void)
|
||||||
|
{
|
||||||
|
return drive_ctrl_object.target_speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_set_current_speed_value(int speed_percent)
|
||||||
{
|
{
|
||||||
drive_ctrl_object.current_speed = speed_percent;
|
drive_ctrl_object.current_speed = speed_percent;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int drive_ctrl_get_speed_value(void)
|
int drive_ctrl_get_current_speed_value(void)
|
||||||
{
|
{
|
||||||
return drive_ctrl_object.current_speed;
|
return drive_ctrl_object.current_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_set_turn_speed_value(int speed_percent)
|
||||||
|
{
|
||||||
|
drive_ctrl_object.turn_speed = speed_percent;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int drive_ctrl_get_turn_speed_value(void)
|
||||||
|
{
|
||||||
|
return drive_ctrl_object.turn_speed;
|
||||||
|
}
|
||||||
|
@ -12,8 +12,12 @@ int drive_ctrl_init(void);
|
|||||||
|
|
||||||
int drive_ctrl_set_speed_left(int speed_percent);
|
int drive_ctrl_set_speed_left(int speed_percent);
|
||||||
int drive_ctrl_set_speed_right(int speed_percent);
|
int drive_ctrl_set_speed_right(int speed_percent);
|
||||||
int drive_ctrl_set_speed_value(int speed_percent);
|
int drive_ctrl_set_target_speed_value(int speed_percent);
|
||||||
int drive_ctrl_get_speed_value(void);
|
int drive_ctrl_get_target_speed_value(void);
|
||||||
|
int drive_ctrl_set_current_speed_value(int speed_percent);
|
||||||
|
int drive_ctrl_get_current_speed_value(void);
|
||||||
|
int drive_ctrl_set_turn_speed_value(int speed_percent);
|
||||||
|
int drive_ctrl_get_turn_speed_value(void);
|
||||||
|
|
||||||
|
|
||||||
#endif /* SOURCE_APPLICATION_INCLUDE_DRIVE_CTRL_H_ */
|
#endif /* SOURCE_APPLICATION_INCLUDE_DRIVE_CTRL_H_ */
|
||||||
|
@ -6,10 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
#include "queue.h"
|
||||||
|
#include "stack.h"
|
||||||
|
#include "kernel.h"
|
||||||
#include "drive_ctrl.h"
|
#include "drive_ctrl.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
@ -86,31 +91,35 @@ int shell_commands_init(void)
|
|||||||
|
|
||||||
static void *drive_turn_right_cb(const char *param)
|
static void *drive_turn_right_cb(const char *param)
|
||||||
{
|
{
|
||||||
int speed = drive_ctrl_get_speed_value();
|
drive_halt_cb(NULL);
|
||||||
drive_ctrl_set_speed_left(abs(speed));
|
int turn_speed = drive_ctrl_get_turn_speed_value();
|
||||||
if(speed > 0)
|
for(int i = 0; i < turn_speed; i++) {
|
||||||
speed *= -1;
|
drive_ctrl_set_speed_left(i);
|
||||||
drive_ctrl_set_speed_right(speed);
|
drive_ctrl_set_speed_right(-1 * i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *drive_turn_left_cb(const char *param)
|
static void *drive_turn_left_cb(const char *param)
|
||||||
{
|
{
|
||||||
int speed = drive_ctrl_get_speed_value();
|
drive_halt_cb(NULL);
|
||||||
drive_ctrl_set_speed_right(abs(speed));
|
int turn_speed = drive_ctrl_get_turn_speed_value();
|
||||||
if(speed > 0)
|
for(int i = 0; i < turn_speed; i++) {
|
||||||
speed *= -1;
|
drive_ctrl_set_speed_right(i);
|
||||||
drive_ctrl_set_speed_left(speed);
|
drive_ctrl_set_speed_left(-1 * i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *drive_boost_cb(const char *param)
|
static void *drive_boost_cb(const char *param)
|
||||||
{
|
{
|
||||||
int speed = drive_ctrl_get_speed_value();
|
int speed = drive_ctrl_get_target_speed_value();
|
||||||
speed += 10;
|
speed += 10;
|
||||||
drive_ctrl_set_speed_value(speed);
|
drive_ctrl_set_target_speed_value(speed);
|
||||||
drive_ctrl_set_speed_left(speed);
|
drive_ctrl_set_speed_left(speed);
|
||||||
drive_ctrl_set_speed_right(speed);
|
drive_ctrl_set_speed_right(speed);
|
||||||
|
|
||||||
@ -119,9 +128,9 @@ static void *drive_boost_cb(const char *param)
|
|||||||
|
|
||||||
static void *drive_retard_cb(const char *param)
|
static void *drive_retard_cb(const char *param)
|
||||||
{
|
{
|
||||||
int speed = drive_ctrl_get_speed_value();
|
int speed = drive_ctrl_get_target_speed_value();
|
||||||
speed -= 10;
|
speed -= 10;
|
||||||
drive_ctrl_set_speed_value(speed);
|
drive_ctrl_set_target_speed_value(speed);
|
||||||
drive_ctrl_set_speed_left(speed);
|
drive_ctrl_set_speed_left(speed);
|
||||||
drive_ctrl_set_speed_right(speed);
|
drive_ctrl_set_speed_right(speed);
|
||||||
|
|
||||||
@ -130,32 +139,77 @@ static void *drive_retard_cb(const char *param)
|
|||||||
|
|
||||||
static void *drive_halt_cb(const char *param)
|
static void *drive_halt_cb(const char *param)
|
||||||
{
|
{
|
||||||
drive_ctrl_set_speed_left(0);
|
int current_speed = drive_ctrl_get_current_speed_value();
|
||||||
drive_ctrl_set_speed_right(0);
|
if(current_speed > 0) {
|
||||||
|
for(int i = current_speed; i > 0; i--) {
|
||||||
|
drive_ctrl_set_current_speed_value(i);
|
||||||
|
drive_ctrl_set_speed_left(i);
|
||||||
|
drive_ctrl_set_speed_right(i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int i = current_speed; i < 0; i++) {
|
||||||
|
drive_ctrl_set_current_speed_value(i);
|
||||||
|
drive_ctrl_set_speed_left(i);
|
||||||
|
drive_ctrl_set_speed_right(i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *drive_forward_cb(const char *param)
|
static void *drive_forward_cb(const char *param)
|
||||||
{
|
{
|
||||||
int speed = drive_ctrl_get_speed_value();
|
int target_speed = drive_ctrl_get_target_speed_value();
|
||||||
if(speed < 0)
|
int current_speed = drive_ctrl_get_current_speed_value();
|
||||||
speed = abs(speed);
|
if(target_speed < 0)
|
||||||
drive_ctrl_set_speed_value(speed);
|
target_speed = abs(target_speed);
|
||||||
drive_ctrl_set_speed_left(speed);
|
drive_ctrl_set_target_speed_value(target_speed);
|
||||||
drive_ctrl_set_speed_right(speed);
|
if(current_speed < target_speed) {
|
||||||
|
for(int i = current_speed; i < target_speed; i++) {
|
||||||
|
drive_ctrl_set_current_speed_value(i);
|
||||||
|
drive_ctrl_set_speed_left(i);
|
||||||
|
drive_ctrl_set_speed_right(i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int i = current_speed; i > target_speed; i--) {
|
||||||
|
drive_ctrl_set_current_speed_value(i);
|
||||||
|
drive_ctrl_set_speed_left(i);
|
||||||
|
drive_ctrl_set_speed_right(i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *drive_backward_cb(const char *param)
|
static void *drive_backward_cb(const char *param)
|
||||||
{
|
{
|
||||||
int speed = drive_ctrl_get_speed_value();
|
int target_speed = drive_ctrl_get_target_speed_value();
|
||||||
if(speed > 0)
|
int current_speed = drive_ctrl_get_current_speed_value();
|
||||||
speed *= -1;
|
if(target_speed > 0)
|
||||||
drive_ctrl_set_speed_value(speed);
|
target_speed *= -1;
|
||||||
drive_ctrl_set_speed_left(speed);
|
drive_ctrl_set_target_speed_value(target_speed);
|
||||||
drive_ctrl_set_speed_right(speed);
|
if(current_speed > target_speed) {
|
||||||
|
for(int i = current_speed; i > target_speed; i--) {
|
||||||
|
drive_ctrl_set_current_speed_value(i);
|
||||||
|
drive_ctrl_set_speed_left(i);
|
||||||
|
drive_ctrl_set_speed_right(i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(int i = current_speed; i < target_speed; i++) {
|
||||||
|
drive_ctrl_set_current_speed_value(i);
|
||||||
|
drive_ctrl_set_speed_left(i);
|
||||||
|
drive_ctrl_set_speed_right(i);
|
||||||
|
sleep_ms(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user