Compare commits
4 Commits
495b18fc2f
...
a39791ab14
Author | SHA1 | Date |
---|---|---|
|
a39791ab14 | |
|
23a1d2e19c | |
|
f56262b195 | |
|
2a8436ddbe |
|
@ -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
|
|
@ -28,27 +28,50 @@ void all_motors_start() {
|
||||||
servo_mv_r(RIGHT_PROP_GPIO, RIGHT_PROP_START_PPM);
|
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) {
|
switch(pin) {
|
||||||
case MAIN_PROP_GPIO:
|
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;
|
break;
|
||||||
case LEFT_PROP_GPIO:
|
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;
|
break;
|
||||||
case RIGHT_PROP_GPIO:
|
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;
|
break;
|
||||||
default:
|
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){
|
void motor_process(char*msg){
|
||||||
char servo_index = msg[4];
|
char servo_index = msg[4];
|
||||||
char servo_mode = msg[5];
|
char servo_mode = msg[5];
|
||||||
int lv;
|
int lv, offset;
|
||||||
char action[5];
|
char action[5];
|
||||||
unsigned int pin;
|
unsigned int pin;
|
||||||
|
|
||||||
|
@ -82,7 +105,7 @@ void motor_process(char*msg){
|
||||||
strcpy(msg, "ESC_STOPPED");
|
strcpy(msg, "ESC_STOPPED");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
sscanf(&msg[6], " %i ", &lv );
|
sscanf(&msg[6], " %i %i", &lv, &offset );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (servo_index == 'M')
|
if (servo_index == 'M')
|
||||||
|
@ -93,6 +116,11 @@ void motor_process(char*msg){
|
||||||
else
|
else
|
||||||
if (servo_index == 'R')
|
if (servo_index == 'R')
|
||||||
pin = RIGHT_PROP_GPIO;
|
pin = RIGHT_PROP_GPIO;
|
||||||
|
else
|
||||||
|
if (servo_index == 'P') {
|
||||||
|
advance_both(msg, &lv, offset);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
eprintf("[motors] index not valid (%c)\n", servo_index);
|
eprintf("[motors] index not valid (%c)\n", servo_index);
|
||||||
strcpy(msg, "ESC_INDX_NOK");
|
strcpy(msg, "ESC_INDX_NOK");
|
||||||
|
@ -108,7 +136,7 @@ void motor_process(char*msg){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '%':
|
case '%':
|
||||||
map_esc_per(pin, &lv);
|
lv = map_esc_per(pin, lv);
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -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.
|
// 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
|
// 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"
|
// Radio pipe addresses for the 2 nodes to communicate. From "TxTunnel.h"
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue