Compare commits
No commits in common. "2a3d2b33b4019264ece12bb0bceae463360e0b9f" and "8455cb88c0ee5e5c38e7163be964072e4aee5296" have entirely different histories.
2a3d2b33b4
...
8455cb88c0
|
@ -27,22 +27,8 @@
|
||||||
|
|
||||||
#define MAIN_PROP_GPIO RPI_V2_GPIO_P1_13
|
#define MAIN_PROP_GPIO RPI_V2_GPIO_P1_13
|
||||||
|
|
||||||
#define MAIN_PROP_START_PPM 1065
|
#define MAIN_PROP_START_PPM 1060
|
||||||
#define MAIN_PROP_IDLE_PPM 1065
|
|
||||||
#define MAIN_PROP_STOP_PPM 2400
|
#define MAIN_PROP_STOP_PPM 2400
|
||||||
#define MAIN_PROP_MAX_PPM 2020
|
|
||||||
|
|
||||||
#define LEFT_PROP_START_PPM 1065
|
|
||||||
#define LEFT_PROP_IDLE_PPM 1065
|
|
||||||
#define LEFT_PROP_STOP_PPM 2400
|
|
||||||
#define LEFT_PROP_MAX_PPM 2020
|
|
||||||
|
|
||||||
#define RIGHT_PROP_START_PPM 1065
|
|
||||||
#define RIGHT_PROP_IDLE_PPM 1065
|
|
||||||
#define RIGHT_PROP_STOP_PPM 2400
|
|
||||||
#define RIGHT_PROP_MAX_PPM 2020
|
|
||||||
|
|
||||||
#define ESC_WAIT_PPM 1005
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __PIN_CONFIG_H__
|
#endif // __PIN_CONFIG_H__
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
/*
|
/*
|
||||||
TMRh20 2014
|
TMRh20 2014
|
||||||
Angel garcía 2019
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
version 2 as published by the Free Software Foundation.
|
version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Hover Controller
|
/** General Data Transfer Rate Test
|
||||||
* This program manage all the RF communications and electronic elements
|
* This example demonstrates basic data transfer functionality with the
|
||||||
* communication.
|
updated library. This example will display the transfer rates acheived using
|
||||||
* The code here manage rf intereactions and pass messages to the dispatcher.
|
the slower form of high-speed transfer using blocking-writes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../rfudp/TxTunnel.h"
|
#include "../rfudp/TxTunnel.h"
|
||||||
|
@ -79,12 +78,11 @@ int main(int argc, char** argv) {
|
||||||
if(gpioInitialise()<0) {
|
if(gpioInitialise()<0) {
|
||||||
perror("[pigpio] gpioInitialise error");
|
perror("[pigpio] gpioInitialise error");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
}else{
|
||||||
|
servo_mv_r(MAIN_PROP_GPIO, 0);
|
||||||
|
servo_mv_r(LEFT_PROP_GPIO, 0);
|
||||||
|
servo_mv_r(RIGHT_PROP_GPIO, 0);
|
||||||
}
|
}
|
||||||
// initialize all motors
|
|
||||||
all_motors_zero(); // set PPM to 0
|
|
||||||
sleep(1); // wait 1 sec
|
|
||||||
all_motors_stop(); // set PPM to stop
|
|
||||||
|
|
||||||
|
|
||||||
// This opens two pipes for these two nodes to communicate
|
// This opens two pipes for these two nodes to communicate
|
||||||
// back and forth.
|
// back and forth.
|
||||||
|
|
|
@ -8,49 +8,16 @@ void motor_esc_initialize(unsigned int pin) {
|
||||||
//servo_mv_r(pin, 0);
|
//servo_mv_r(pin, 0);
|
||||||
//sleep(0.5);
|
//sleep(0.5);
|
||||||
servo_mv_r(pin, MAIN_PROP_STOP_PPM);
|
servo_mv_r(pin, MAIN_PROP_STOP_PPM);
|
||||||
|
usleep(10000);
|
||||||
//sleep(1);
|
//sleep(1);
|
||||||
//servo_mv_r(pin, MAIN_PROP_START_PPM);
|
//servo_mv_r(pin, MAIN_PROP_START_PPM);
|
||||||
}
|
}
|
||||||
|
|
||||||
void all_motors_stop() {
|
|
||||||
servo_mv_r(MAIN_PROP_GPIO, MAIN_PROP_STOP_PPM);
|
|
||||||
servo_mv_r(LEFT_PROP_GPIO, LEFT_PROP_STOP_PPM);
|
|
||||||
servo_mv_r(RIGHT_PROP_GPIO, RIGHT_PROP_STOP_PPM);
|
|
||||||
}
|
|
||||||
void all_motors_zero() {
|
|
||||||
servo_mv_r(MAIN_PROP_GPIO, 0);
|
|
||||||
servo_mv_r(LEFT_PROP_GPIO, 0);
|
|
||||||
servo_mv_r(RIGHT_PROP_GPIO, 0);
|
|
||||||
}
|
|
||||||
void all_motors_start() {
|
|
||||||
servo_mv_r(MAIN_PROP_GPIO, MAIN_PROP_START_PPM);
|
|
||||||
servo_mv_r(LEFT_PROP_GPIO, LEFT_PROP_START_PPM);
|
|
||||||
servo_mv_r(RIGHT_PROP_GPIO, RIGHT_PROP_START_PPM);
|
|
||||||
}
|
|
||||||
|
|
||||||
int map_esc_per(unsigned int pin, int *lv) {
|
|
||||||
switch(pin) {
|
|
||||||
case MAIN_PROP_GPIO:
|
|
||||||
*lv = 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);
|
|
||||||
break;
|
|
||||||
case RIGHT_PROP_GPIO:
|
|
||||||
*lv = map(*lv, 0, 100, RIGHT_PROP_IDLE_PPM, RIGHT_PROP_MAX_PPM);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*lv = map(*lv, 0, 100, ESC_MIN, ESC_MAX);
|
|
||||||
}
|
|
||||||
return *lv;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
char action[5];
|
char action[5];
|
||||||
unsigned int pin;
|
|
||||||
|
|
||||||
static bool started=false;
|
static bool started=false;
|
||||||
|
|
||||||
|
@ -58,65 +25,30 @@ void motor_process(char*msg){
|
||||||
eprintf("Act: %s\n", action);
|
eprintf("Act: %s\n", action);
|
||||||
|
|
||||||
if (strcmp(action, "START") == 0) {
|
if (strcmp(action, "START") == 0) {
|
||||||
if (!started) {
|
if (!started){
|
||||||
eprintf("Estarting ESCs\n");
|
eprintf("Estarting ESC\n");
|
||||||
all_motors_stop(); // set all motors to stop position
|
motor_esc_initialize(MAIN_PROP_GPIO);
|
||||||
usleep(10000); // wait just a bit (10000 µs or 0,01 secs)
|
servo_mv_r(MAIN_PROP_GPIO, MAIN_PROP_START_PPM);
|
||||||
all_motors_start(); // set all to start speed
|
|
||||||
//servo_mv_r(MAIN_PROP_GPIO, MAIN_PROP_START_PPM);
|
|
||||||
started=true;
|
started=true;
|
||||||
|
}else
|
||||||
strcpy(msg, "ESC_STARTED");
|
|
||||||
} else {
|
|
||||||
eprintf("ESC already started\n");
|
eprintf("ESC already started\n");
|
||||||
|
|
||||||
strcpy(msg, "ESC_IS_STARTED");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else
|
} else
|
||||||
if (strcmp(action, "STOP") == 0) {
|
if (strcmp(action, "STOP") == 0) {
|
||||||
//servo_mv_r(MAIN_PROP_GPIO, MAIN_PROP_STOP_PPM);
|
servo_mv_r(MAIN_PROP_GPIO, MAIN_PROP_STOP_PPM);
|
||||||
all_motors_stop(); // Stops all ESCs
|
|
||||||
started=false;
|
started=false;
|
||||||
|
|
||||||
strcpy(msg, "ESC_STOPPED");
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
sscanf(&msg[6], " %i ", &lv );
|
sscanf(&msg[6], " %i ", &lv );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (servo_index == 'M')
|
if (servo_index == 'M') {
|
||||||
pin = MAIN_PROP_GPIO;
|
servo_mv_r(MAIN_PROP_GPIO, lv);
|
||||||
else
|
} else
|
||||||
if (servo_index == 'L')
|
if (servo_index == 'L') {
|
||||||
pin = LEFT_PROP_GPIO;
|
servo_mv_r(LEFT_PROP_GPIO, lv);
|
||||||
else
|
|
||||||
if (servo_index == 'R')
|
|
||||||
pin = RIGHT_PROP_GPIO;
|
|
||||||
else {
|
|
||||||
eprintf("[motors] index not valid (%c)\n", servo_index);
|
|
||||||
strcpy(msg, "ESC_INDX_NOK");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (servo_mode) {
|
} else
|
||||||
case ' ':
|
if (servo_index == 'R') {
|
||||||
if (lv < 500)
|
servo_mv_r(RIGHT_PROP_GPIO, lv);
|
||||||
servo_mode = '%';
|
|
||||||
else
|
|
||||||
servo_mode = 'R';
|
|
||||||
break;
|
|
||||||
case '%':
|
|
||||||
map_esc_per(pin, &lv);
|
|
||||||
break;
|
|
||||||
case 'R':
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
eprintf("[motors] mode not valid (%c)\n", *mode);
|
|
||||||
strcpy(msg, "ESC_MODE_NOK");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
servo_mv_r(pin, lv);
|
}
|
||||||
sprintf(msg, "ESC %c%c %i", servo_index, servo_mode, lv);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,5 @@
|
||||||
|
|
||||||
#include "servos.h"
|
#include "servos.h"
|
||||||
void motor_process(char*msg);
|
void motor_process(char*msg);
|
||||||
void all_motors_stop();
|
|
||||||
|
|
||||||
#endif // __MOTORS_H__
|
#endif // __MOTORS_H__
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
#define SERVER_PORT 8080
|
#define SERVER_PORT 8080
|
||||||
#define MAX_MSG_SZ 32
|
#define MAX_MSG_SZ 32
|
||||||
#define RF_CHANNEL 0
|
#define RF_CHANNEL 0
|
||||||
#define MILLIS_WAIT 200
|
|
||||||
|
|
||||||
#define ACK_MODE FALSE
|
#define ACK_MODE FALSE
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,10 @@ TMRh20 2014
|
||||||
version 2 as published by the Free Software Foundation.
|
version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** TxTunnelSender
|
/** General Data Transfer Rate Test
|
||||||
* This programm acts as a middle layer between clients and a nRF24 antenna.
|
* This example demonstrates basic data transfer functionality with the
|
||||||
* It sends to the other node what it receive on the udp socket and answer the sender
|
updated library. This example will display the transfer rates acheived using
|
||||||
* with whatever the node sends back.
|
the slower form of high-speed transfer using blocking-writes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "TxTunnel.h"
|
#include "TxTunnel.h"
|
||||||
|
@ -183,10 +183,10 @@ int main(int argc, char** argv){
|
||||||
|
|
||||||
loop_start = millis();
|
loop_start = millis();
|
||||||
radio.startListening();
|
radio.startListening();
|
||||||
while ( !radio.available() && (millis() - loop_start) < MILLIS_WAIT) {
|
while ( !radio.available() && (millis() - loop_start) < 200) {
|
||||||
// wait till receive or timeout
|
// wait till receive or timeout
|
||||||
}
|
}
|
||||||
if (millis() - loop_start >= MILLIS_WAIT) {
|
if (millis() - loop_start >= 100) {
|
||||||
eprintf("Not Response.\n\r");
|
eprintf("Not Response.\n\r");
|
||||||
strcpy(buffer,"TxERR\0");
|
strcpy(buffer,"TxERR\0");
|
||||||
n=strlen(buffer);
|
n=strlen(buffer);
|
||||||
|
|
Loading…
Reference in New Issue