To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 374
373  |  375
Subject: 
Code for simple robot
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Sun, 28 Apr 1996 15:42:00 GMT
Original-From: 
Larry Randall <lrand@ctsAVOIDSPAM.com>
Viewed: 
1758 times
  
It is possible that there are those out there that may be as bad at 'C' as I
am, so for what is worth, here is my code that is working.  My bot,
Rug-Runner, with HandyBoard, has been wandering around my house for about
half an hour now without getting into any trouble, except on a throw rug
which grabs the tail wheel.

Rug-runner is a simple bot using converted servos as motors, any reversable
DC moter will work.  It has two bumper switches that switch a ground to the
bit when hit.  The scanning Sonar is the Polaroid 6500 unit with standard
unconverted servo.  See previous messages for hockup.  Please don't flame my
code.  If you can use some of it, good.  If you can't, throw it away.

It you would like any explanations or other info about this code, please
feel free to email me.

Good luck to all, and have as much fun as I did.  (am having)

Larry

cut here ------------------------------------------- code below --------

/************************************************************************/
/*      Rug_Runner Robot        by: Larry Randall       Apr. 96         */
/*      now at main4.c                                              */
/*      Operation Modes = Wander, Avoid                                 */
/************************************************************************/

int lm = 0;                   /* Left Motor # */
int rm = 1;                   /* Right Motor # */
int left = 13; /* Left Bump bit */
int right = 11; /* Right Bump bit */
int full_speed = 100;         /* approx 2 sec/ft */
int mid_speed = 80;
int half_speed = 50;          /* approx 3 sec/ft */
int slow_speed = 25;
int zero_speed = 0;           /* motor stop */
int lspeed = mid_speed;       /* Left Speed */
int rspeed = mid_speed;       /* Right Speed */
/* Max scan # is 4680 || Min scan # 1400 */
int scan_60_deg = 1000; /* 60 degrees */
int scan_45_deg = 750;
int scan_30_deg = 500;
int scan_array[41];
int scan_count = 20; /* Start at center */
int scan_step = 50; /* Approx. 3 Degrees */
int dir_flag = -1; /* moving left cw */
int r_limit = 1970; /* Max right angle - Lo number */
int center_line = 2970;       /* Sonar dead ahead */
int l_limit = 3970; /* Max left angle - Hi number */
int sonar_position = center_line; /* Start at center */
int feet;
int inches;

/***************************************************************************
****/
/* main4.lis    file reads as follows */
/*
============================================================================ */
/* servo.icb by Motarola & Randy Sargent */
/* sonar.icb by Motarola & Randy Sargent */
/* servo.c by Ann Wright */
/* main4.c   (this file) */
/***************************************************************************
*****/


void main()
{
   servo_on();
   sleep(0.5);
   servo(sonar_position); /* Start at center */
   sleep(0.5);
   start_process(send_ping(), 150);

   while(1)
   {
      set_speed(lspeed+20, rspeed);     /* adjust left drift */
      set_speed(lspeed, rspeed);
      check_path();
      get_bump();
   }
}

void send_ping()
{
   while(1)
   {
      ping(0);
      msleep(35L); /* wait 35 milliseconds */
      sonar_time=sonar_time/150;
      do_scan(sonar_time); /* reposition sonar servo */
      feet=sonar_time/12;
      inches=sonar_time-(feet*12);
      printf("dist: %d' %d\"\n",feet,inches);
      defer();
   }
}

int do_scan(int object)
{
   scan_array[scan_count] = object;
   if((scan_count < 2) || (scan_count > 39)) dir_flag = -dir_flag;
   scan_count = scan_count + dir_flag;
   sonar_position = r_limit + (scan_step * scan_count);
   servo(sonar_position);
}

int check_path()
{
   int ptr = 9;

   while(ptr < 30)
   {
      if(scan_array[ptr] < 15)
      {
         if (random(0) < 5000) go_reverse(500L); /* a bit of randomness */
         if (ptr < 21) left_spin(45);
            else right_spin(45);
      }
      ptr = ptr + 1;
   }
}

int right_spin(int deg)
{
   int delay = (2300 / (91 / deg));   /* values found by expermintation */
   set_speed(slow_speed, -slow_speed);
   msleep((long) (delay));
}

int left_spin(int deg)
{
   int delay = (2300 / (91 / deg));
   set_speed(-slow_speed, slow_speed);
   msleep((long) (delay));
}

void set_speed(int setleft, int setright)
{
   motor(lm, setleft);
   motor(rm, setright);
}

long go_reverse(long delay)
{
   set_speed(-half_speed, -half_speed);
   msleep(delay);
}

void get_bump()
{
   if (digital(left) > 0)
   {
      go_reverse(750L); /* back up */
      right_spin(75); /* turn away */
   }
   if (digital(right) > 0)
   {
      go_reverse(750L);
      left_spin(60);
   }
}


************ Larry Randall ****************
              If it works
              Don't fix it!
************ lrand@cts.com ****************



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR