Show Posts
Pages: [1] 2
1  Topics / Robotics / Re: Artificial Intelligence??? on: March 16, 2014, 10:15:17 am
If you consider maze solving a form of artificial intelligence, then here's a link to curriculum I've developed describing how to build and program an Arduino controlled robot to get through a maze: http://www.udemy.com/nanomouse. I also have a support page for this project at http://sites.google.com/site/mbbackus.
2  Topics / Education and Teaching / New, Free Artificial Intelligence with Arduinos Course on: November 23, 2013, 11:20:06 am
I'm putting together a free online course that shows how to build and program a very simple micromouse with an Arduino Nano: http://www.udemy.com/nanomouse. I'm using it with my middle and high school students, and am looking for feedback. As it is right now, it probably has enough instruction for a motivated beginner to be successful, but having a mentor who's familiar with programming and/or Arduinos would definitely be helpful. It's a great project for somebody who's played with Lego robotics and is looking for the next step. The curriculum is not finished yet-I'm working on it as fast as I can.
3  Using Arduino / Sensors / Re: IR sensor and ambient light on: November 23, 2013, 11:11:01 am
I explain how to do something like this in my free online course: http://www.udemy.com/nanomouse
4  Development / Suggestions for the Arduino Project / Arduino 1.0.2 extremely slow due to rxtxSerial.dll on: December 07, 2012, 10:31:54 am
I was hoping the new version of the IDE 1.0.2 would include a fix for the extreme lag some are experiencing. The fix has been developed and is well documented by eried. It involves using an alternative rxtxSerial.dll file he created. See http://arduino.cc/forum/index.php/topic,46977.0.html for more info.
5  Development / Suggestions for the Arduino Project / Arduino Nano .inf file on: December 07, 2012, 10:25:35 am
I was hoping the 1.0.2 version of the IDE would include an .inf file for the Arduino Nano so that when I plugged it into my computer, I'd see something in my Device Manager that said Arduino Nano instead of USB Serial Port (COM##). Any chance that can be added to the next version, and/or better yet a release of such an .inf file be made early? Thanks.
6  Using Arduino / Sensors / Re: Parallax Mouse Sensor Kit on: November 25, 2012, 12:07:02 pm
I'm sorry, but I don't have time to explain my code as you have requested. On the upside, you don't really need to understand it to use it (that's the wonderful thing about libraries). I've written a library for this kit which you can download and use. It even comes complete with sample code. It is available for download towards the bottom of the following page: https://sites.google.com/site/mbbackus/robotics/bread-board-bot. Hope this helps. Best of luck with your project.
7  Using Arduino / Programming Questions / Re: Wierd Behavior when including Servo Class within my own Robot Class on: October 28, 2012, 02:07:29 am
Found the problem!

Parallax documentation lists the following precaution:

LED connected to digital pin 13 after reset. Digital pin 13 also controls a servo if it’s connected to port 13, so it may twitch in response to this on/off signal when the program restarts.

I switched to pins 10 & 11 and everything's working as it should (aside from the annoyance of having to include Servo.h in the main sketch).
8  Using Arduino / Programming Questions / Re: Wierd Behavior when including Servo Class within my own Robot Class on: October 27, 2012, 10:31:11 pm
The main sketch and the BBBot.h files didn't change from my previous post (post #3).
9  Using Arduino / Programming Questions / Re: Wierd Behavior when including Servo Class within my own Robot Class on: October 27, 2012, 06:34:21 pm
I went ahead and changed the code as suggested. My BBBot.cpp file now looks as follows:

Code:
#include "BBBot.h"

BBBot::BBBot()
{}

void BBBot::begin(byte leftPin, byte rightPin)
{
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
  servoLeft.attach(leftPin);
  servoRight.attach(rightPin);
}

void BBBot::forward(int power)
{
  servoLeft.writeMicroseconds(1500 + power);
  servoRight.writeMicroseconds(1500 - power);
}

void BBBot::stop()
{
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
}

Unfortunately, I still see the glitch every single time I reset the robot and run the program again.
10  Using Arduino / Programming Questions / Re: Wierd Behavior when including Servo Class within my own Robot Class on: October 27, 2012, 10:46:28 am
I did as you suggested and it's working now. I have a few questions though.

1) Why do I have to wait until setup in order to access hardware? Why can't I do so when creating objects in a constructor?

2) When my robot first starts, the left motor twitches 3 times-always the exact same twitch each time. Any way to get rid of this?

3) Last but not least, what would be the best way to not need to include the Servo library in my main sketch? Seems to me that if it's included in the .h file that should be good enough, but of course this causes an error. I've looked online and there are suggestions, but I can't get any of them to work.

My code as of now is as follows.

Main sketch:
Code:
#include "BBBot.h"
#include "Servo.h"

BBBot myBot;

void setup()
{
  myBot.begin(13,12);
  myBot.forward(200);
  delay(1000);
  myBot.stop();
}

void loop() {}

BBBot.h file:
Code:
#ifndef BBBot_h
#define BBBot_h

#include "Arduino.h"
#include "Servo.h"

class BBBot
{
  public:
    BBBot();
    void begin(byte leftPin, byte rightPin);
    void forward(int power);
    void stop();
  private:
    Servo servoLeft;
    Servo servoRight;
};

#endif

BBBot.cpp file:
Code:
#include "BBBot.h"

BBBot::BBBot()
{}

void BBBot::begin(byte leftPin, byte rightPin)
{
  servoLeft.attach(leftPin);
  servoRight.attach(rightPin);
}

void BBBot::forward(int power)
{
  servoLeft.writeMicroseconds(1500 + power);
  servoRight.writeMicroseconds(1500 - power);
}

void BBBot::stop()
{
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
}
11  Using Arduino / Programming Questions / Wierd Behavior when including Servo Class within my own Robot Class on: October 27, 2012, 01:30:36 am
I'm putting together a very cheap differential drive robot using Parallax's continuous rotation servos. A pulse of 1500 keeps the servos still, a pulse of 1700 makes them rotate counter clockwise as fast as they can go, and a pulse of 1300 makes them rotate clockwise as fast as they can go. Because of the motors' orientation, I must provide the left one with a pulse of 1700 and the right with a pulse of 1300 to get the robot to drive forward. When I use the following code, the robot drives forward as expected:
Code:
#include "Servo.h"

Servo servoLeft;
Servo servoRight;

void setup()
{
  servoLeft.attach(13);
  servoRight.attach(12);
  servoLeft.writeMicroseconds(1700);
  servoRight.writeMicroseconds(1300);
  delay(1000);
}

void loop() {}

However, when I try to do the same thing with a library I wrote called BBBot (short for Bread Board Bot), the robot rotates instead of driving forward. I checked what was being written to the servos, and it was 1700 & 1300 as well.
Code:
#include "BBBot.h"
#include "Servo.h"

BBBot myBot(13,12);

void setup()
{
  myBot.forward(200);
}

void loop() {}

Here's the BBBot.h code:
Code:
#ifndef BBBot_h
#define BBBot_h

#include "Arduino.h"
#include "Servo.h"

class BBBot
{
  public:
    BBBot(byte leftMotorPin, byte rightMotorPin);
    void forward(int power);
  private:
    Servo servoLeft;
    Servo servoRight;
};

#endif

And here's the BBBot.cpp code:
Code:
#include "BBBot.h"

BBBot::BBBot(byte leftPin, byte rightPin)
{
  servoLeft.attach(leftPin);
  servoRight.attach(rightPin);
}

void BBBot::forward(int power)
{
  servoLeft.writeMicroseconds(1500 + power);
  servoRight.writeMicroseconds(1500 - power);
}

Not sure why, but I'm guessing it has something to do with timers getting messed up within the servo class. Any ideas?
12  Using Arduino / Programming Questions / Re: Shiftin MSBPOST Argument Not an option on: October 04, 2012, 12:04:30 am
Go to http://arduino.cc/forum/index.php/topic,124808.0.html and scroll to the bottom.
13  Using Arduino / Sensors / Re: Parallax Mouse Sensor Kit on: September 30, 2012, 02:02:21 pm
I got it working really well using the Advanced hardware configuration shown in the documentation. Here's the code:

Code:
#define sclk 5 //Define pin 5 as clock
#define sdio 6 //Define pin 6 as data

//Mouse sensor register addresses
#define CONF 0x1B
#define LORES 0x80
#define CHNG  0x80
#define OFLOW 0x18
#define NEG 0x80

byte stat;
byte quality;
byte ovfl;
byte readx;
byte ready;

int dx;
int dy;
int x;
int y;

void WriteAddr(byte address, byte data)
{
  pinMode(sdio,OUTPUT);
  shiftOut(sdio,sclk,MSBFIRST,address|0x80);
  shiftOut(sdio,sclk,MSBFIRST,data);
}

int ReadAddr(byte address)
{
  int data;
  pinMode(sdio,OUTPUT);
  shiftOut(sdio,sclk,MSBFIRST,address);
  delayMicroseconds(100);
  pinMode(sdio,INPUT);
  data = shiftIn(sdio,sclk,MSBFIRST);
  return data;
}

void setup()
{
  Serial.begin(9600);
  pinMode(sclk,OUTPUT);
  digitalWrite(sclk,LOW);  
  delay(100);
  WriteAddr(CONF,LORES);
}

void loop()
{
  stat = ReadAddr(0x16);
  if(stat & CHNG == 0)
  {
  } else {
    if(stat & OFLOW)
    {
      ovfl = 10;
    }
    readx = ReadAddr(0x03);
    if(readx & NEG)
    {
      dx = -1*(256-readx);
    } else {
      dx = readx;
    }
    x = x + dx;
    ready = ReadAddr(0x02);
    if(ready & NEG)
    {
      dy = -1*(256-ready);
    } else {
      dy = ready;
    }
    y = y + dy;
    quality = ReadAddr(0x04);
    Serial.print(dx,DEC);
    Serial.print("\t");
    Serial.print(x,DEC);
    Serial.print("\t");
    Serial.print(dy,DEC);
    Serial.print("\t");
    Serial.print(y,DEC);
    Serial.print("\t");
    Serial.print(quality,DEC);
    if(ovfl > 0)
    {
      ovfl = ovfl - 1;
      Serial.print("\t");
      Serial.print("Overflow");
    }
    Serial.print("\n");
  }
}
14  Using Arduino / Programming Questions / Re: Shiftin MSBPOST Argument Not an option on: September 30, 2012, 02:00:58 pm
I finally got it working, and it's working really well. I was forgetting to toggle the dataline's pinmode between input and output before the shift commands. Thanks so much.

15  Using Arduino / Programming Questions / Re: Shiftin MSBPOST Argument Not an option on: September 30, 2012, 01:23:15 am
Well, I tried the SPI approach, but didn't have any success. I hooked the clock up to pin 13 and the data line to pin 11 (I actually tried pin 12 too to no avail). If it helps at all, I'm trying to read a change in x and y position from the optical sensor in Parallax's Mouse Sensor Kit: https://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/677/Default.aspx?txtSearch=mouse+sensor+kit

Here's the code I tried:
Code:
#include <SPI.h>

//Mouse sensor register addresses
#define CONF 0x1B
#define LORES 0x80
#define CHNG  0x80
#define OFLOW 0x18
#define NEG 0x80

byte stat;
byte dx;
byte dy;
byte quality;
byte ovfl;

int x;
int y;

void WriteAddr(byte address, byte data)
{
  SPI.transfer(address|0x80);
  SPI.transfer(data);
}

int ReadAddr(byte address)
{
  byte data;
  data = SPI.transfer(address);
  return data;
}

void setup()
{
  delay(2000);
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE3);
  delay(100);
  WriteAddr(CONF,LORES);
 
}

void loop()
{
  stat = ReadAddr(0x16);
  dx = ReadAddr(0x03);
  dy = ReadAddr(0x02);
  quality = ReadAddr(0x04); 
  Serial.println(dx,BIN);
}
Pages: [1] 2