Skip to content

In Which Carbot Exhibits Self Control

November 11, 2014

Here is carbot running autonomously. It is “seeing” the door ahead of it and turning left to avoid it. This one shot looks fine but it worked less well with a makeshift box and book barrier – I’m not sure why. I may have to implement a bluetooth reporting scheme so i can see what it is seeing.

In both videos the forward motion is at 50% duty cycle so it’s a bit jittery.

In terms of weight and balance, carbot weighs 425 grams with 88g load on the front and 336 on the rear.
Re-thinking my original arduino carbot, it must have weighed 15-20g more than i originally thought (with the three sensors) so 370g with an extra 10g on the front wheels so 77g. The total weight is still much greater but the front wheel load doesn’t seem so bad.
Here’s the code for the mainline

//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=100,dist; //time to live limit, distance to barrier
	printf("Carbot Mule Here\n");
		dist=pingq(); //printf("<%d ",dist);
		if (dist>60){ // more than 1 ft from barrier(60 cm round trip)
			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
			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
#include <olduino.c>
#include <nstdlib.c>
#include "softpwm.c"
#include "pingBN.c"

Here’s the code for the software PWM which still doesn’t seem quite right but works for now.

//softpwm.c routines for olduino software pulse width management.
//Oct 12 - pwmstep included in pwmcycleN
void analogWrite(unsigned int bit, unsigned int val){
	if (bit<2){
		dct[bit]=val>>5; //step down range to 0..7
void pwmcycleN(unsigned int howmany){ //run howmany*8 steps of the software pwm
	unsigned int step; //toggle table index
	unsigned char * togglep=toggle; //togglep will be in a register
	while(howmany-- >0){
		togglep[dct[0]]|=1; //set the end of the duty cycle for bit 0
		togglep[dct[1]]|=2; //set the end of the duty cycle for bit 1
		togglep[0]^=~PIN4; //set up with current state of port4 low bits
		togglep[0]&=0x03; //only the pwm bits are set
			PIN4^=togglep[step];	//toggles the bit off if the duty cycle is over
			//printf("dct[0]=%cx, step %d, toggle[%d]=%cx, PIN4=%cx\n",dct[0],step, step, toggle[step],PIN4);

From → Uncategorized

Leave a Comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: