Author Topic: 50 dollar robot with DC motors instead of servos. How do i implement and progra  (Read 1863 times)

0 Members and 1 Guest are viewing this topic.

Offline ishkabibleTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
hi I'm looking at building my first robot and Google's magic wonders brought me here. I have a firm understanding of C/C++ but completely lack any real knowledge of how to build or implement hardware that wasn't already setup for me. i grew an interest in it to further my understanding of programing. i have looked over source code of both the Axon and $50 robot and i don't seem to see any thing that might be used for DC motors(that doesn't mean it's not there). this wouldn't be a problem if i wanted to follow the tut exactly but i want to use DC motors. I'm sure this is possible but i don't know the following:
*how to hook it up to the MCU
*the Syntax necessary to control it

i am assuming the best way to do it would be to make some type of addition to SOR_utils that allowed me to use DC motors in almost the same way as the hacked servos. just to be clear i am not looking for an addition to the Axon, just the $50 robots code. O and i need to know how to attach the DC motors to the MCU of the $50 robot. thx  
i also have just recently read about H-bridges. from what i have read i would assume that that would be the way to do this but im still very unclear on how to build an H-bridge for any robot. so some type explanation of how to build an H-bridge and again how to implement it in the $50 robot would be very nice.   
« Last Edit: March 20, 2010, 03:40:16 PM by ishkabible »

Offline Pratheek

  • Contest Winner
  • Robot Overlord
  • ****
  • Posts: 125
  • Helpful? 3
    • Probots
If you are planning to use DC Motors for the $50 robot, then you will have to make quite a few changes to the circuit and the code.

First of all you, will have to use an H-Bridge to control the DC Motors. There are many commercial pre-built ones available in all most all online robot stores, which you can directly connect to the $50 robot's board to control your motors. Or you can build one yourself with the vast number of H Bridge ICs available(L293, L298, etc). Do search "H Bridge circuits" for more information.

Secondly, after you have the H Bridge, you will have to make a few changes to the code. The code will depend on the H Bridge you select and the connections you have made. Making the code changes should be quite easy if you have understood how the H Bridge works and how to program the MCU.

By the way, any specific reason why do want to use only DC motors?

Offline ishkabibleTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
No there is no real purely logical reason that i want to use them but the want to use them steams from having some old erecter set wheels that are missing any  type of screws to connect them to servos and i figured i could weld the DC motor and Wheel together because there made of steel. thx ill look more in to pre-built H-birdges.   

Offline ishkabibleTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
i was wondering if these additions to SOR_utils would work. I'm confused as to weather or not the H-bridge(L293D) has its own ports and if so how to call on them. so I'm posting the code i think will work to see if this can be explained further.
Code: [Select]
/****************************************************************************
*
*   Copyright (c) 2007 [url=http://www.societyofrobots.com]www.societyofrobots.com[/url]
*   (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.
*
* SoR Utilities v1, March 10th, 2007
*
****************************************************************************/

//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 "buffer.h" // include buffer function library
//#include "uart.h" // include uart function library
//#include "rprintf.h" // include printf function library
//#include "timer.h" // include timer function library (timing, PWM, etc)
#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)
#define PORT_ALL_ON( port_letter, number ) port_letter |= (number)
#define PORT_ALL_OFF( port_letter, number ) port_letter &= ~(number)
#define FLIP_PORT( port_letter, number ) port_letter ^= (1<<number)
#define PORT_IS_ON( port_letter, number ) ( port_letter & (1<<number) )
#define PORT_IS_OFF( port_letter, number ) !( port_letter & (1<<number) )
#define L293D_A P2_0
#define L293D_B P2_1
#define L293D_E P2_2

//************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);
}
void DC_Forward(signed long int speed){
        PORT_ON(PORTD, 1);            
        PORT_ON(PORTD, 0);          
L293D_A = 1;            
        L293D_B = 0;  
        L293D_E = 1;
        delay_cycles(speed);
        PORT_OFF(PORTD, 1);
        PORT_OFF(PORTD, 0);
}
void DC_Backward(signed long int speed){
        PORT_ON(PORTD, 1);            
        PORT_ON(PORTD, 0);
L293D_A = 0;            
        L293D_B = 1;            
        L293D_E = 1;
        delay_cycles(speed);
        PORT_OFF(PORTD, 1);
        PORT_OFF(PORTD, 0);
}
void DC_breaks(){
        L293D_A = 0;            
        L293D_B = 0;            
        L293D_E = 0;
        PORT_OFF(PORTD, 1);
        PORT_OFF(PORTD, 0);
}
//***************************************

Ok I'm editing my post because i now understand that there are pins but i am still not sure how to call on them my best guess is in my code L293D_A = 0 shuts off some port i think but i don't know witch port or if it even dose shut off a port. so some clarity on that would be grate.
« Last Edit: March 21, 2010, 01:33:33 PM by ishkabible »

 


Get Your Ad Here

data_list