Compare commits

...

4 Commits

Author SHA1 Message Date
Angel Garcia a39791ab14 updated RF24 pin config on middle layer 2019-06-04 10:37:57 +02:00
Angel Garcia 23a1d2e19c fix silly errors motors 2019-06-04 10:33:17 +02:00
Angel Garcia f56262b195 Init files ftw
well, they are systemd service files... but you get the idea...
2019-06-04 10:21:23 +02:00
Angel Garcia 2a8436ddbe motors new features
avance both
2019-06-04 10:20:47 +02:00
4 changed files with 67 additions and 10 deletions

View File

@ -0,0 +1,14 @@
[Unit]
Description=Hover Controller
After=syslog.target
[Service]
RestartSec=2s
Type=simple
User=root
Group=root
ExecStart=/home/pi/hover-programs/hover-controller/hover-controller
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@ -28,27 +28,50 @@ void all_motors_start() {
servo_mv_r(RIGHT_PROP_GPIO, RIGHT_PROP_START_PPM);
}
int map_esc_per(unsigned int pin, int *lv) {
int map_esc_per(unsigned int pin, int lv) {
int lv_new;
switch(pin) {
case MAIN_PROP_GPIO:
*lv = map(*lv, 0, 100, MAIN_PROP_IDLE_PPM, MAIN_PROP_MAX_PPM);
lv_new = map(lv, 0, 100, MAIN_PROP_IDLE_PPM, MAIN_PROP_MAX_PPM);
break;
case LEFT_PROP_GPIO:
*lv = map(*lv, 0, 100, LEFT_PROP_IDLE_PPM, LEFT_PROP_MAX_PPM);
lv_new = map(lv, 0, 100, LEFT_PROP_IDLE_PPM, LEFT_PROP_MAX_PPM);
break;
case RIGHT_PROP_GPIO:
*lv = map(*lv, 0, 100, RIGHT_PROP_IDLE_PPM, RIGHT_PROP_MAX_PPM);
lv_new = map(lv, 0, 100, RIGHT_PROP_IDLE_PPM, RIGHT_PROP_MAX_PPM);
break;
default:
*lv = map(*lv, 0, 100, ESC_MIN, ESC_MAX);
lv_new = map(lv, 0, 100, ESC_MIN, ESC_MAX);
}
return *lv;
return lv_new;
}
void advance_both(char*msg, int *lv, int offset){
int lv_r, lv_l;
int offset_base = *lv/4; //get offset to ajust
lv_r = lv_l = *lv; // asign base level
eprintf("lv: %i,\tlv_r:%i\t,lv_l:%i\n", *lv, lv_r, lv_l);
// offset values if necesary
if( offset < 50)
lv_r = lv_r - offset_base;
if( offset < 50)
lv_l = lv_l - offset_base;
eprintf("lv: %i,\tlv_r:%i\t,lv_l:%i\n", *lv, lv_r, lv_l);
// map to real values
lv_r = map_esc_per(RIGHT_PROP_GPIO, lv_r);
lv_l = map_esc_per(LEFT_PROP_GPIO, lv_l);
// ajust motor speed
servo_mv_r(RIGHT_PROP_GPIO, lv_r);
servo_mv_r(LEFT_PROP_GPIO, lv_l);
}
void motor_process(char*msg){
char servo_index = msg[4];
char servo_mode = msg[5];
int lv;
int lv, offset;
char action[5];
unsigned int pin;
@ -82,7 +105,7 @@ void motor_process(char*msg){
strcpy(msg, "ESC_STOPPED");
return;
} else {
sscanf(&msg[6], " %i ", &lv );
sscanf(&msg[6], " %i %i", &lv, &offset );
}
if (servo_index == 'M')
@ -93,6 +116,11 @@ void motor_process(char*msg){
else
if (servo_index == 'R')
pin = RIGHT_PROP_GPIO;
else
if (servo_index == 'P') {
advance_both(msg, &lv, offset);
return;
}
else {
eprintf("[motors] index not valid (%c)\n", servo_index);
strcpy(msg, "ESC_INDX_NOK");
@ -108,7 +136,7 @@ void motor_process(char*msg){
break;
}
case '%':
map_esc_per(pin, &lv);
lv = map_esc_per(pin, lv);
break;
case 'R':
break;

View File

@ -25,7 +25,8 @@ using namespace std;
// See http://www.airspayce.com/mikem/bcm2835/group__constants.html#ga63c029bd6500167152db4e57736d0939 and the related enumerations for pin information.
// Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_32MHZ);
//RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_32MHZ);
RF24 radio(RF_CE_PIN, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_32MHZ);
// Radio pipe addresses for the 2 nodes to communicate. From "TxTunnel.h"

View File

@ -0,0 +1,14 @@
[Unit]
Description=TxTunnelSender
After=syslog.target
[Service]
RestartSec=2s
Type=simple
User=root
Group=root
ExecStart=/home/pi/hover-programs/rfudp/TxTunnelSender
Restart=on-failure
[Install]
WantedBy=multi-user.target