Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taranis sbus support #153

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.project
.metadata
bin/
library/lib/
tmp/
*.tmp
*.bak
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.0.5
* add support for Taranis SBUS remote control.

1.0.4
* fix missing stddef.h include in i2c.h
* add kmartin36's PRU encoder robustness improvement
Expand Down Expand Up @@ -187,4 +190,4 @@
0.1.0
* installs on Blue as well and Black

// indentation is with spaces to allow copy/paste into debian/changelog
// indentation is with spaces to allow copy/paste into debian/changelog
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
librobotcontrol (1.0.5) stable; urgency=low
* add support for Taranis SBUS remote control.
-- Per Dalgas Jakobsen <pdj@knaldgas.dk> Mon, 4 Mar 2019 16:04:00 +0000


librobotcontrol (1.0.4) stable; urgency=low
* fix missing stddef.h include in i2c.h
* add kmartin36's PRU encoder robustness improvement
Expand Down
29 changes: 29 additions & 0 deletions examples/src/rc_calibrate_sbus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @example rc_calibrate_sbus.c
*
* Running the rc_calibrate_sbus example will print out raw data to
* the console and record the min and max values for each
* channel. These limits will be saved to disk so future sbus reads
* will be scaled correctly.
*
* Make sure the transmitter and receiver are paired before
* testing. The satellite receiver remembers which transmitter it is
* paired to, not your BeagleBone.
*/

#include <stdio.h>
#include <rc/sbus.h>

int main()
{
printf("Please connect a SBUS satellite receiver and make sure\n");
printf("your transmitter is on and paired to the receiver.\n");
printf("\n");
printf("Press ENTER to continue or anything else to quit\n");
getchar();

// run the calibration routine
rc_sbus_calibrate_routine();

return 0;
}
12 changes: 11 additions & 1 deletion examples/src/rc_dsm_passthrough.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ int main(int argc, char *argv[])
return -1;
}
rc_adc_cleanup();

if(rc_servo_init ()){
fprintf(stderr,"failed to initialize servos\n");
return -1;
}
if(rc_servo_power_rail_en(1)){
fprintf(stderr,"failed to enable power rail\n");
return -1;
Expand Down Expand Up @@ -153,6 +158,11 @@ int main(int argc, char *argv[])
rc_usleep(25000);
}
printf("\n");

if(mode == POWERON){
rc_servo_cleanup ();
}
rc_dsm_cleanup();

return 0;
}
}
173 changes: 173 additions & 0 deletions examples/src/rc_sbus_passthrough.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
* @example rc_sbus_passthrough.c
*
* This sends all sbus data straight out the servo channels as they
* come in. When running this program the BBB acts exactly like a
* normal SBUS receiver.
*
* You must specify SERVO or ESC mode with -s or -e to turn om or off
* the 6V power rail. Sending 6V into an ESC may damage it!!!
*
* Raw data is also printed to the terminal for monitoring.
*/

#include <stdio.h>
#include <getopt.h>
#include <signal.h>
#include <rc/sbus.h>
#include <rc/servo.h>
#include <rc/time.h>
#include <rc/adc.h>

static int running;

typedef enum p_mode_t{
NONE,
POWERON,
POWEROFF
} p_mode_t;

// function to be called every time new a new SBUS packet is received.
static void __send_pulses(void)
{
int i, val;

// send single to working channels
for(i=1; i<=8; i++){
val=rc_sbus_ch_raw(i);
if(val>0) rc_servo_send_pulse_us(i,val);
}

// print all channels
printf("\r");
for(i=1;i<=RC_MAX_SBUS_ANALOG_CHANNELS;i++){
val = rc_sbus_ch_raw(i);
if (val != 0) {
printf("% 4d ", val);
}
}
for(i=1;i<=RC_MAX_SBUS_BINARY_CHANNELS;i++){
printf("% 1d ", rc_sbus_ch_binary(i));
}
fflush(stdout);
return;
}

// interrupt handler to catch ctrl-c
static void __signal_handler(__attribute__ ((unused)) int dummy)
{
running=0;
return;
}


// printed if some invalid argument was given
static void __print_usage(void)
{
printf("\n");
printf(" Options\n");
printf(" -s Enable 6V power rail for servos.\n");
printf(" -e Disable 6V power rail for ESCs.\n");
printf(" -h Print this messege.\n\n");
return;
}

// main routine
int main(int argc, char *argv[])
{
int c;
p_mode_t mode = NONE;

// parse arguments
opterr = 0;
while ((c = getopt(argc, argv, "seh")) != -1){
switch (c){

case 's': // enable power for servos
mode = POWERON;
break;

case 'e': // disbable power for ESCs
mode = POWEROFF;
break;

case 'h': // show help messege
__print_usage();
return -1;
break;

default:
fprintf(stderr,"Invalid Argument \n");
__print_usage();
return -1;
}
}

if(mode == NONE){
fprintf(stderr,"You must select a power mode -s or -e\n");
__print_usage();
return -1;
}

if(rc_sbus_init()==-1) return -1;

// if power has been requested, make sure battery is connected!
if(mode == POWERON){
// read adc to make sure battery is connected
if(rc_adc_init()){
fprintf(stderr,"ERROR: failed to run rc_adc_init()\n");
return -1;
}
if(rc_adc_batt()<6.0){
fprintf(stderr,"ERROR: battery disconnected or insufficiently charged to drive motors\n");
return -1;
}
rc_adc_cleanup();

if(rc_servo_init ()){
fprintf(stderr,"failed to initialize servos\n");
return -1;
}
if(rc_servo_power_rail_en(1)){
fprintf(stderr,"failed to enable power rail\n");
return -1;
}
}

// print header
printf("1:Thr ");
printf("2:Roll ");
printf("3:Pitch ");
printf("4:Yaw ");
printf("5:Kill ");
printf("6:Mode ");
printf("7:Aux1 ");
printf("8:Aux2 ");
printf("\n");

printf("Waiting for SBUS Connection");
fflush(stdout);

// set signal handler so the loop can exit cleanly
signal(SIGINT, __signal_handler);
running=1;

rc_sbus_set_callback(&__send_pulses);
while(running){
if(rc_sbus_is_connection_active()==0){
printf("\rSeconds since last SBUS packet: ");
printf("%0.1f ", rc_sbus_nanos_since_last_packet()/1000000000.0);
printf(" ");
fflush(stdout);
}
rc_usleep(25000);
}
printf("\n");

if(mode == POWERON){
rc_servo_cleanup ();
}
rc_sbus_cleanup();

return 0;
}
Loading