Author Topic: Robots in progress..  (Read 13440 times)

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Robots in progress..
« on: June 22, 2013, 07:05:52 am »
Hello!
Just received two Digisparks! Saw them when they were still unfunded on kickstarter and finally got my hands on them.
I build really tiny robots and have plans to robotize some digisparks.
Some of my older miniature robot work can be found at www.CJHRC.com (shameless plug, I don't sell any products!)I will post some pictures of some robots made with Digisparks soon!
Love the idea. Great work!  8)
-Casey

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #1 on: July 06, 2013, 06:30:21 pm »
First up, I practiced PWM my digispark LED.
This makes a heartbeat with fades and delay.
I have never used arduino IDE until now even though I've had it around for some time.
Forgive me if I'm doing it all wrong.

Quote
void setup() {               
  pinMode(1, OUTPUT); 
}

void pwm(unsigned char length,unsigned char brightness){
  for (int i=0;i<brightness;i++){
  analogWrite(1, i);
  delay(length);                 
  }
  for (int i=brightness;i>0;i--){
  analogWrite(1,i);
  delay(length);
  }
}
void loop() {
  pwm(1,255);    //delay length in milliseconds(fade speed in thousandths of a second),brightness on scale of 0-255
  pwm(1,255);
  digitalWrite(1,LOW);
  delay(1000);
}

So that works fine to flash the onboard LED in a neat fashion. Easy enough..


I then added a custom three pin requirement pwm h-bridge motor shield to one of my digispark.
I think it seems to be working properly. Looks like a head of a robot.
More to come. I tested some motors and need to build a gearbox and motor set.
the two pair of wires coming off are for the motors. There is three I/O left for peripherals.


I have mini 90mah lipo batteries coming from China for power.
« Last Edit: July 06, 2013, 06:38:42 pm by caseyjholmes »

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #2 on: July 13, 2013, 07:22:44 am »
Had a half hour last night to write and test some simple PWM routines for the motor driver.
Found some old swiss 10/1 micro planetary gear motors I want to use also. I'm going to build a base for the robot shortly.

I haven't decided if I want it to follow lines or avoid objects or both.
I had a line sensor but it seems to not be working so I may need to build more.

Here is some fun test code I made for adding a button to a digispark on pin5 and blinking the LED.
it does several different things while testing if's, for's, whiles and counting variables.
Getting my feet wet with this IDE.

Quote
const int button=5;
const int LED=1;

int buttonstate=0;
// the setup routine runs once when you press reset:
void setup() {               
  pinMode(1, OUTPUT); 
  pinMode(button,INPUT);
 
}
unsigned char count = 0;

//LED PWM ramp up and down function
void pwm(unsigned char length,unsigned char brightness){
  for (int i=0;i<brightness;i++){
  analogWrite(LED, i);
  delay(length);                 
  }
  for (int i=brightness;i>0;i--){
  analogWrite(LED,i);
  delay(length);
  }
//main loop
}
void loop() {
  digitalWrite(LED,LOW);
  buttonstate = digitalRead(button);
  if (!buttonstate){
   pwm(LED,255);    //delay length in milliseconds(fade speed in thousandths of a second),brightness on scale of 0-255
  pwm(LED,255);
  digitalWrite(LED,LOW);
  delay(1000);
  count = count + 1;
  if (count == 3){  //if count makes it to three button presses or
  //3 LED cycles while being held, blink on and off 10 times
    for (int b=0;b<10;b++){
    digitalWrite(LED,HIGH);
    delay(100);
    digitalWrite(LED,LOW);
    delay(100);
    }
  }
  if (count == 6){
    //debounce: at six counts, holds LED on until you remove your finger..
    //never turns the LED on if you didn't hold button.
    buttonstate=digitalRead(button);
    if (!buttonstate){
    digitalWrite(LED,HIGH);
    while (digitalRead(LED)==HIGH){
      buttonstate=digitalRead(button);
      if (digitalRead(buttonstate)==HIGH){
        digitalWrite(LED,LOW);
      }
     }
    }
    count = 0;  //resets counter
  }
   
  }
   
 
}

and here is some basic motor driver code for my PWM H-bridge shield.

Quote
const int M1=0;  //motor 1,  right?!
const int M2=1; //motor 2, left!
const int enable=2; //h-bridge enable pins
const int sensor 1  //sensor 1 add here
const int sensor 2  //sensor 2 add here
const int sensor 3 //sensor 3 add here
int sensorstate1  //add
int sensorstate2  //add
int sensorstate2 //add  table edge sensor?

void setup(){
pinMode(M1,OUTPUT);  //motor1 pin is output
pinMode(M2,OUTPUT);   //motor2 pin is output
pinMode(enable,OUTPUT); //motor enable pin is output

}

void motorsoffstop(){           //brake
digitalWrite(enable,HIGH  );
analogWrite(M1,127);
analogWrite(M2,127);
}

void motorsonstop(){              //idle
digitalWrite(enable,LOW);
analogWrite(M1,127); 
analogWrite(M2,127);
}

//main motor driving routine for forward, reverse, left and right
//just vary value in velocity when calling function
void drive(unsigned char velocity1, unsigned char velocity2){
digitalWrite(enable,LOW);
analogWrite(M1,velocity1);
analogWrite(M2,velocity2);
}

void loop(){
motorsoffstop(); //brake rm127 lm127
delay(1000);
motorsonstop(); //idle rm127 lm127
delay(1000);
drive(255,0);  //forward rm255 lm0 full speed
delay(1000);
drive(0,255); //backward rm0 lm255 full speed
delay(1000);
drive(255,255); //left  rm255 lm255 full speed
delay(1000);
drive(0,0);    //right rm0 lm0 full speed
delay(1000);
}

Mark

  • Full Member
  • ***
  • Posts: 196
Re: Robots in progress..
« Reply #3 on: July 13, 2013, 04:08:04 pm »
Casey

Its starting to look very good.
Its much easier to "Getting my feet wet with this IDE. " when you have a simple project.

You may wish to look at BlinkWithoutDelay and how you can use millis() instead of delay.

I use an anaology of filling a swimming pool.
You can stand there holding the hose until its fill ( aka delay )
or you can come back every 5 mins to see if its full while you do something else ( aka millis() ).

Code: [Select]
        if(millis() - LastChange > 150)    // change every 150mS which should be a xxHz flash
        {
          LastChange = millis();     // save the last time you blinked the LED
          if (ledState == LOW)
              ledState = HIGH;
          else
              ledState = LOW;
        }

Above is an example of blinking a LED without using delay().

This sketch was from one where two different programs run in the same controller, hence delay couldn't be used.

Mark


caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #4 on: July 13, 2013, 09:25:57 pm »
Thanks for the examples! I noticed something along the lines of removing delays in an example in The arduino or digispark IDE kit somewhere.  I will look more into this and study your examples! Much appreciated.  Any input is always welcome. 


I received the batteries today in the mail.  Just need to cook up a fancy chassis for these fancy Swiss motors.  Always so busy lately and moving around, my lathe and mill are In Storage with the PC. 
Digispark turns out to be a perfect little on the go programming practice chip..
Love how it just hangs off the USB port on my laptop.   8)
Ill try to incorporate that feature into the design of the robot.

Since the batteries are lithium, I have also come up with the idea of building in a small lithium battery charger circuit and hacking it into the digispark. So the batteries should recharge when the robot is plugged in to USB by the digispark. I need to get a hub for testing so I don't fry my laptop and look up some USB charger circuits online. From what I remember they were fairly simple to construct. I think I even have a tiny lipo battery charger for USB laying around somewhere.

I haven't tried to bypass the regulator and run the digipsark at 3.7v yet. I'm not sure if it will do this.. but I received two battery cells to work with just in case. I will try for 3.7v first, and if it won't work, I'll boost it to 7.4. Although, when fully charged it's more like 4.2v per cell so about 8.4v max.
We used to bypass the regulator on the MegaBitty robot controller board until we finally figured out we could swap the Mega8 chip for the Mega8L and get single cell operation.

when it comes to robots, I really like to build. Programming comes second. I was never very good at it, but it seems I have slowly improved over the years, thankfully. Now I can understand how to form enough C code to get by with the basics. I've been working on learning more complex things with bare AVR chips and AVRISPMKII programming for a few years. The digispark is a nice break from the harder register flipping operations I'm used to as of late.

Another thing I need to look up when I get time, is if Digispark is compatible with interrupts as with bare AVR chips and the ISP. One of these days..

Until next time. 

A few more ideas to contemplate:
Digispark color sensor shield
object sensor and line sensor shield
directional dual light sensor shield
1" OLED shield (possible or not?)
Digispark iPad app and connector
Solar Digispark shield or low power digispark etc etc for the BEAM robot guys and external powerless projects
« Last Edit: July 13, 2013, 11:15:10 pm by caseyjholmes »

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #5 on: July 15, 2013, 05:08:45 pm »
small amount of progress on the chassis today, even started installing the brains and brawn of the operation. Have some batteries and some other peripherals to go on next, including some wheels for rubber band tank treads I may lathe up if I can get away with it at work or something.

I've had these Swiss geared motors for ten years now... since Robomax in Oregon. Finally found a use for them. lol





The batteries I got last time for my other robots were smaller and even came with charge/discharge protection. These batteries are larger and have no added circuitry. I got ripped, but oh well. I'll try and use them anyway. Little fire hazards.
There's the line sensor PCB I will likely put on this robot eventually, if not a larger one.



caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #6 on: July 16, 2013, 06:37:25 pm »
why did this code work yesterday and not today?
I'm getting an error "expected intilializer before numeric constant"


Mark

  • Full Member
  • ***
  • Posts: 196
Re: Robots in progress..
« Reply #7 on: July 16, 2013, 10:35:13 pm »
My first thoughts are how did it work yesterday.

You need some semicolons after the const int sensor lines.

I don't suppose it might have defaulted to the wrong board and programmer??


Mark

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #8 on: July 17, 2013, 05:24:18 am »
Oh, sheesh!
Talk about a newbie mistake. 
Ok thanks  :o  I should have seen that one coming. 
Board and programmer was right, my code was wrong (as usual!)


caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #9 on: July 20, 2013, 09:07:22 pm »
So I have the motors wired up and tested.
Pretty neat driving a couple small high precision motors via USB like that.
I may try and make a small low power robot arm one of these days with USB control. That would be neat.

Well here is some pics with the robot plugged into a USB extension cable for programming and the motor wires terminated and tucked away.

I just moved into the new place and started unpacking my tiny lathe so I may get a chance to do the wheels soon. HAd a bit of a break there and haven't done much other than test the motors and PWM H-bridges to the basic program.

I want to learn how to remove the delays next.. along with finish the hardware part of the chassis.
Then the batteries and USB charger come last with the sensors.






caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #10 on: July 23, 2013, 05:29:39 am »
Assembled the battery last night.  Waiting on a lipo balance adaptor so I can balance the battery while charging, then I can mount it in the robot. 


Unpacked the lathe but still pretty busy.  Not sure when I'll get to it..
Next on the list.


I could also benefit from a digispark programming tool here pretty soon..


I had an idea of making the robot respond to direction keyboard presses from the PC. 
Ill have to look into that.
« Last Edit: July 23, 2013, 06:32:56 am by caseyjholmes »

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #11 on: August 01, 2013, 06:47:32 am »
Lots of delays!
Received the battery cable  then lost it.  Just found it again this morning! Been dealing with finalizing the move and unpacking all my stuff so my room is a nightmare. Ill get back to this ASAP.  I can't leave that cute little robot face sitting there unfinished for much longer hehe
More updates soon :P

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: Robots in progress..
« Reply #12 on: August 05, 2013, 01:10:04 pm »
Amazingly TINY looking stuff! Good luck, will look for more. 
(followed the one robot image link on your web page and it went nowhere)

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #13 on: August 14, 2013, 02:56:50 pm »
My apologies
Been a while since I worked on the page! Ill try and fix it soon. 


A friend at work and I have come up with some custom brackets for this robot to mount tank tread style tracks to it.  We made one of the pieces just right but I just messed up the second piece.  Have to remake one.  Progress is going slow but in hoping to have an update with pictures soon.  This will be one cool looking robots!

caseyjholmes

  • Newbie
  • *
  • Posts: 25
Re: Robots in progress..
« Reply #14 on: August 15, 2013, 06:43:34 pm »
OK here's an update as promised.
While at work I managed to get the robot chassis complete aside from the pulley wheels. I will have to make those on my lathe, or steal them from a toy or something and shape them as needed. Likely use my lathe.

I plan to put four pulley wheels on the robot. One on each extreme lower corner of the sidewall chassis we made at work.
Then I need to more pulley wheels with set screws to slip on the swiss motor shafts. I'll use rubber bands for tracks, since that has seemed to work so well in the past on other robots.

I have the batteries but haven't figured out how to install them in a neat way just yet, along with onborad USB charger.
I'll get to it. I'm gonna put some thought and time into this robot.

Here's some pics of the progress. The side aluminum channel was perfectly cut to length and positioned on the robot around the motor bell and motor oilite bearings/bushing for a perfect fit, then a channel was dug for the wires coming off the endbell.
Love the looks.

[/URL]

[/URL]

[/URL]

[/URL]

[/URL]

I love being an under-paid self-proclaimed engineer. Here's me and the things I build at work between sneaking around building robots.
[/URL]
« Last Edit: August 15, 2013, 06:49:02 pm by caseyjholmes »