go_away

Author Topic: $50 robot programmed and nothing  (Read 3351 times)

0 Members and 1 Guest are viewing this topic.

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
$50 robot programmed and nothing
« on: February 12, 2008, 08:46:16 AM »
Now that my AVRISP MKII works, thanks to yesterdays firmware upgrade, I finally got my atmeta168 programmed.  Hooray!  Too bad nothing seems to work.  Can anyone help me out?

Thanks.

Offline atmegaman

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #1 on: February 12, 2008, 11:29:31 AM »
What exactly is not working?

Does any part of the board heat up? (regulator, chip itself, etc.)
Did you program the servos?

A little bit more information would be helpful

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #2 on: February 12, 2008, 12:38:07 PM »
Well, I did some more testing and finally got some other code to work, but I can't get Admin's .hex file to center the servo to work and I can't tell if the photovore code for the $50 robot is working because it's not doing anything.

The code I used that actually made my board do something is rox2007's from this post.

Now, I'm assuming that I missed a step or something along the way.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: $50 robot programmed and nothing
« Reply #3 on: February 12, 2008, 02:16:30 PM »
read the third paragraph here then report your findings:
http://www.societyofrobots.com/robot_faq.shtml#circuit_debug

you need to tell us what isn't working for us to help you ;)

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #4 on: February 12, 2008, 02:55:58 PM »
I'm using 6 1.2v batteries for 7.2v.  My servo bus is reading about 7v and sensor bus is 4.5v-5v.  It's an analog multimeter and not a very good one ;).  From what I can tell, everything is put together correctly.  At this point I don't think I know enough to distinguish between what isn't working from normal behavior.

The code I referenced in my previous post works (makes my servo run).  I think it would really help my debugging to have a copy of the uncompiled code for centering the servo.  Partially because I'm not sure how exactly it works and I'm sure it would be a helpful reference.

I'm an old dog trying to learn new tricks.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: $50 robot programmed and nothing
« Reply #5 on: February 12, 2008, 03:21:45 PM »
to get your center servo code, use the photovore code, but make this one mod:

Code: [Select]
while(1)
   servo_left(35);

Place it inside and at the top of the while(1) loop already there in Photovore_v1.c

Then just compile it and upload it.

Also, measure both buses while everything is plugged in and the servo code is running.

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #6 on: February 12, 2008, 03:57:19 PM »
This is what my code looks like now:

Code: [Select]
/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_on();//turn LED on


while(1)
{
servo_left(35);
/*
//store sensor data
sensor_left=a2dConvert8bit(5);
sensor_right=a2dConvert8bit(4);


//detects more light on left side of robot
if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold)
{//go left
servo_left(44);
servo_right(44);
}

//detects more light on right side of robot
else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold)
{//go right
servo_left(25);
servo_right(25);
}

//light is about equal on both sides
else
{//go straight
servo_left(25);
servo_right(44);
}
*/

/* Servo Test Code
i=250;
while(i>0)
{
servo_left(40);
i--;
}

i=250;
while(i>0)
{
servo_left(24);
i--;
}
*/

//rprintf("Initialization Complete\r\n");

//output message to serial (use hyperterminal)
//print("Hello, World! Read My Analog: %u\r\n", sensor_0);

delay_cycles(500);//a small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/

Now, is my servo supposed to continuously turn until I adjust to pot properly?  Because it isn't turning at all right now.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: $50 robot programmed and nothing
« Reply #7 on: February 12, 2008, 09:52:14 PM »
For the code, you forgot a while(1) . . .

Code: [Select]
/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_on();//turn LED on


while(1)
{
while(1)
servo_left(35);
/*
//store sensor data
sensor_left=a2dConvert8bit(5);
sensor_right=a2dConvert8bit(4);


Are you sure you got the servo plugged into the right spot? It should rotate . . . What happens when you run that other code you said works?

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #8 on: February 13, 2008, 07:59:53 AM »
I fixed it to add the while(1).  The other code makes it rotate and it doesn't stop no matter how I adjust the pot.  Also, I have the servo plugged into PD0.

While fiddling with it last night, I commented out all of the delay_cycles and made the servo work.  Unfortunately, adjusting the pot still had no effect.

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #9 on: February 13, 2008, 11:26:25 AM »
Could my voltage be the problem and not the code?  The servo manual says that it can be run within a 4.8v - 6v range.  My battery pack is 7.2v.  I'll try it out and see if it changes anything.

Update:
Voltage in is now 6.0v and no change in status.
« Last Edit: February 13, 2008, 11:45:37 AM by javafiend »

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #10 on: February 13, 2008, 04:12:54 PM »
I created a new project using AVR Studio using relevant parts of SoR_Utils and Photovore_v1 and came up with this:

Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2007 www.societyofrobots.com
*   (please link back if you use this code!)
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License version 2 as
*   published by the Free Software Foundation.
*
*   Alternatively, this software may be distributed under the terms of BSD
*   license.
*
* Photovore v1, March 10th, 2007
* Simple case-based method for a robot that chases light.
*
*
****************************************************************************/
//AVR includes
#include <avr/io.h>     // include I/O definitions (port names, pin names, etc)
#include <avr/interrupt.h> // include interrupt support

//AVRlib includes
#include "global.h" // include global settings
#include "a2d.h" // include A/D converter function library

//define port functions; example: PORT_ON( PORTD, 6);
#define PORT_ON( port_letter, number ) port_letter |= (1<<number)
#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)


//************CONFIGURE PORTS************
//configure ports for input or output - specific to ATmega8
void configure_ports(void)
{
DDRC = 0x00;  //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF;  //configure all D ports for output
DDRB = 0xC7;  //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex')
}
//***************************************

//************DELAY FUNCTIONS************
//wait for X amount of cycles (23 cycles is about .992 milliseconds)
//to calculate: 23/.992*(time in milliseconds) = number of cycles
void delay_cycles(unsigned long int cycles)
{
while(cycles > 0)
cycles--;
}
//***************************************

//*********SIMPLIFIED FUNCTIONS**********
//functions to make coding easier for a beginner
//but could cause port mixup confusion for intermediate users
void LED_on(void)
{
PORT_OFF(PORTD, 4);//turn LED on
}
void LED_off(void)
{
PORT_ON(PORTD, 4);//turn LED off
}
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
//delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
//delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
//delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
//delay_cycles(200);
}
//***************************************


int main(void)
{
//declare variables here



/*********ADD YOUR CODE BELOW THIS LINE **********/
LED_on();//turn LED on


while(1)
{
while(1)
servo_left(35);



//rprintf("Initialization Complete\r\n");

//output message to serial (use hyperterminal)
//print("Hello, World! Read My Analog: %u\r\n", sensor_0);

delay_cycles(500);//a small delay to prevent crazy oscillations
}
/*********ADD YOUR CODE ABOVE THIS LINE **********/

return 0;
}


/*********************COMMAND LIST*************************

delay_cycles(cycles);
Delays - you can make your robot wait for a certain amount of time with this function.
Put the number of computational cycles to delay in the ().
23 cycles is about .992 milliseconds
to calculate: 23/.992*(time in milliseconds to delay) = cycles
Check servo datasheet where it says: 'Direction: Clockwise/Pulse Traveling 1500 to 1900usec'


servo_left(speed); and servo_right(speed);
Commands your servos to rotate at a certain speed.
Vary speed (which represents a delay in cycles) from 20 to 50.
Left is for port D0 and right is for port D1.


LED_on(); and LED_off();
Turns on and off your LED. The LED is on port D4.
By bringing port D4 low, you are turning on the LED.


variable=a2dConvert8bit(pin);
Reads analog pin. For example, set 'pin' to 5 to read PC5.
'variable' will store the value.

***********************************************************/


This makes the servo continuously run.  Now, the only thing that I can tell that is significantly different between the photovore project and this one is potentially the makefile.  Again, I am a complete novice to robot building and electronics so I could be way off base.  I can't seem to get the photovore code to work without using the included makefile though.

Update:
Just created a new project and brought in all of the photovore code with the exception of using the included makefile and the servo runs, but still doesn't stop.  Has anyone heard of a bad batch of HS-311's?

Oh, I don't know if this matters or not, but I can't even get the LED to come on :(
« Last Edit: February 13, 2008, 04:52:41 PM by javafiend »

Offline javafiendTopic starter

  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 0
Re: $50 robot programmed and nothing
« Reply #11 on: February 13, 2008, 08:00:27 PM »
EUREKA!!!!!!!!!!!!  ;D ;D ;D ;D ;D ;D

Ok, I had a flash of inspiration after over a week of frustration.  It occurred to me to look at the tutorial again and look at the upgrade your ATMEGA section - UPGRADE ATmega8 TO ATmega168 (SWAP OUT).  Well, all the code was correct as well as my board.  I just neglected to run through the swap out steps!

I am up and running now and let this be a lesson to all that Admin is always right!

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,658
  • Helpful? 169
    • Society of Robots
Re: $50 robot programmed and nothing
« Reply #12 on: February 17, 2008, 10:00:20 AM »
lol I'm not always right :P

yea, what happened was that you weren't running at the right frequency because of the botched upgrade :P

 


Get Your Ad Here