Advertisement
silver2row

LibRobotControl

Apr 9th, 2023
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.24 KB | None | 0 0
  1. // Trying Out Some Source from LibRobotControl
  2. // For debugging and testing w/ laasyapriya
  3. // W/ some testing from Seth and some source from librobotcontrol theory...
  4.  
  5. #include <robotcontrol.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. #define RC_SERVO_CH_MIN 1
  10. #define RC_SERVO_CH_MAX 8
  11. #define RC_ESC_DEFAULT_MIN_US 1000
  12. #define RC_ESC_DEFAULT_MAX_US 2000
  13.  
  14. int min = RC_SERVO_CH_MIN;
  15. int min_us = RC_ESC_DEFAULT_MIN_US;
  16. int max_us = RC_ESC_DEFAULT_MAX_US;
  17. double servo_pos = 0;
  18. double sweep_limit = 0;
  19. int ch = 1;
  20. double direction = 1;
  21. int frequency_hz = 50;
  22. int i = 0;
  23. int val = 0;
  24. int en = 1;
  25.  
  26. int main() {
  27.         // Main Loop at 50 Hz?
  28.         while(ch == 1) {
  29.             // increase and descrease?
  30.                 servo_pos += direction * sweep_limit / frequency_hz;
  31.  
  32.                 // reset and start from scratch
  33.                 if(servo_pos > sweep_limit) {
  34.                         servo_pos = sweep_limit;
  35.                         direction = -1;
  36.                 }
  37.                 else if(servo_pos < (-sweep_limit)) {
  38.                         servo_pos = -sweep_limit;
  39.                         direction = 1;
  40.                 // The results are in...
  41.                 }
  42.         }
  43.  
  44.         // sleeping or trying to!
  45.         rc_usleep(1000000 / frequency_hz);
  46.         return 0;
  47. }
  48.  
  49. int rc_servo_init(void) {
  50.         // Start and Configure the PRU for sending Servo Pulses...
  51.         while(ch == 1) {
  52.                 ch = 1;
  53.                 rc_set_state(RUNNING);
  54.                 rc_servo_init();
  55.                 rc_make_pid_file();
  56.         }
  57.         return 0;
  58. }
  59. int rc_servo_power_rail_en(en) {
  60.         if(en) {
  61.                 rc_servo_power_rail_en(1);
  62.         }
  63.         return 0;
  64. }
  65.  
  66. int rc_servo_set_esc_range(min_us, max_us) {
  67.         return 0;
  68. }
  69.  
  70. int rc_servo_send_pulse_normalized(int ch, double servo_pos) {
  71.         for(servo_pos = 1; servo_pos <= 8; servo_pos++) {
  72.                 val = ch;
  73.                 if(val > 0) {
  74.                         rc_servo_send_pulse_normalized(servo_pos, val);
  75.                         servo_pos = 1;
  76.                         rc_usleep(100000);
  77.                         servo_pos = -1;
  78.                         rc_usleep(100000);
  79.                 }
  80.         }
  81.         return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement