Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Trying Out Some Source from LibRobotControl
- // For debugging and testing w/ laasyapriya
- // W/ some testing from Seth and some source from librobotcontrol theory...
- #include <robotcontrol.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define RC_SERVO_CH_MIN 1
- #define RC_SERVO_CH_MAX 8
- #define RC_ESC_DEFAULT_MIN_US 1000
- #define RC_ESC_DEFAULT_MAX_US 2000
- int min = RC_SERVO_CH_MIN;
- int min_us = RC_ESC_DEFAULT_MIN_US;
- int max_us = RC_ESC_DEFAULT_MAX_US;
- double servo_pos = 0;
- double sweep_limit = 0;
- int ch = 1;
- double direction = 1;
- int frequency_hz = 50;
- int i = 0;
- int val = 0;
- int en = 1;
- int main() {
- // Main Loop at 50 Hz?
- while(ch == 1) {
- // increase and descrease?
- servo_pos += direction * sweep_limit / frequency_hz;
- // reset and start from scratch
- if(servo_pos > sweep_limit) {
- servo_pos = sweep_limit;
- direction = -1;
- }
- else if(servo_pos < (-sweep_limit)) {
- servo_pos = -sweep_limit;
- direction = 1;
- // The results are in...
- }
- }
- // sleeping or trying to!
- rc_usleep(1000000 / frequency_hz);
- return 0;
- }
- int rc_servo_init(void) {
- // Start and Configure the PRU for sending Servo Pulses...
- while(ch == 1) {
- ch = 1;
- rc_set_state(RUNNING);
- rc_servo_init();
- rc_make_pid_file();
- }
- return 0;
- }
- int rc_servo_power_rail_en(en) {
- if(en) {
- rc_servo_power_rail_en(1);
- }
- return 0;
- }
- int rc_servo_set_esc_range(min_us, max_us) {
- return 0;
- }
- int rc_servo_send_pulse_normalized(int ch, double servo_pos) {
- for(servo_pos = 1; servo_pos <= 8; servo_pos++) {
- val = ch;
- if(val > 0) {
- rc_servo_send_pulse_normalized(servo_pos, val);
- servo_pos = 1;
- rc_usleep(100000);
- servo_pos = -1;
- rc_usleep(100000);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement