Skip to content

Single Sensor Carbot

January 19, 2015

This is just for my record. Carbot as pictured, with the mule software, fails to negotiate turns (doesn’t turn long enough). I am not quite sure why though. As I look at the arduino software it is only using the front sensor to negotiate the turn. I’ll have a better look at the code tomorrow.
15-01-19 carbot

Also for the record, here’s what the ping signal looks like to the logic analyzer for a long distance followed by a short distance.
15-01-19

//olduino carbot mule Nov 11, 2014
#include <olduino.h>
#include <nstdlib.h> //supports c d s x l cx
#include "cpu1802spd4port7.h"
#include "softpwm.h"
#include "carbot.h"
#include "pingBN.h"
void main(){
//try a controlled turn sequence
	unsigned int ttl=200,dist; //time to live limit, distance to barrier
	unsigned char wasdoing='S'; //we were starting
	printf("Carbot Lives\n");
	PIN4=0;out(4,0);
	while(ttl!=00){
		dist=pingq(); printf("<%d ",dist);
		if (dist>60 && wasdoing!='L'){ // more than 1 ft from barrier(60 cm round trip) and we weren't turning
			printf("F\n");
			analogWrite(pwmb,128);//half power right
			analogWrite(pwma,128);//half power left
			digitalWrite(bin1,HIGH); digitalWrite(bin2,LOW);
			digitalWrite(ain1,HIGH); digitalWrite(ain2,LOW);
			pwmcycleN(11);//forward a bit
		}else{
			if (dist<=60) {
				wasdoing='L'; //i was turning left
				printf("L>");
			} else{
				wasdoing='X'; //i was extending the turn
				printf("X>");
			}
			analogWrite(pwmb,255);//full power right
			analogWrite(pwma,255);//full power left
			digitalWrite(bin1,HIGH); digitalWrite(bin2,LOW);
			digitalWrite(ain1,LOW); digitalWrite(ain2,HIGH); //reverse left wheel
			pwmcycleN(11);//turn left a bit
		}
		ttl--; //reduce time to live
	}
	PIN4=0;out(4,0); //kill it all
	printf("done\n");
}
#include <olduino.c>
#include <nstdlib.c>
#include "softpwm.c"
#include "pingBN.c"
int pingfront(){ //ping ahead of the car
  static unsigned long lastpulse=0; //keep us from overrunning the sensors
  #define sensordelay 66 //minimum time between calls
  unsigned long thistime=millis();
  if ((thistime>(lastpulse+sensordelay))||(lastpulse==0)){ //except for the first time we need a healthy delay between pings
    if (lastpulse!=0){//track motion on right sensor after the first time
      olderfcm=oldfcm;
      oldfcm=fcm; 
    }
    fcm=microsecondsTocm(pingtime(fwdpingpin));
    lastpulse=thistime;
    cout <<endl<<"@T="<<thistime<<" f="<<fcm<<endl;
  }
  return fcm;
}
int pingright(){ //ping to right of the car
  static unsigned long lastpulse=0; //keep us from overrunning the sensors
  #define sensordelay 66 //minimum time between calls
  unsigned long thistime=millis();
  if ((thistime>(lastpulse+sensordelay))||(lastpulse==0)){ //except for the first time we need a healthy delay between pings
    if (lastpulse!=0){ //track motion on right sensor after the first time
       olderrcm=oldrcm;
       oldrcm=rcm;
    }
    rcm=microsecondsTocm(pingtime(rtpingpin));
    lastpulse=thistime;
    cout <<endl<<"@T="<<thistime<<" r="<<rcm<<endl;
  }
  return rcm;
}
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: