go away spammer

Author Topic: How to write or register a motor controller in sor_util.h of axon???  (Read 5694 times)

0 Members and 1 Guest are viewing this topic.

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Hi everyone, I still need some help regarding adding an entry to write a motor controller like http://www.robotshop.ca/solarbotics-l298-motor-driver-kit-2.html to the sor_util.h. May I know how can I do it in a step by step basis...?, my club admin really badly to make the sub work as possible.



Thanks mates, a reply would be greatly appreciated!

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #1 on: March 31, 2009, 06:11:18 PM »
It has nothing to do with sor_util.h. You are basically asking how to drive a motor...
The link you give is similar to my motor drivers in the tutorial at http://www.societyofrobots.com/member_tutorials/node/159
In order to drive these sorts of motor/boards you need to understand how PWM works. My above link contains links to a PWM tutorial.
All the info you need is there - but its not a 'software development service' ie learn, understand and be empowered to solve your own problem.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #2 on: March 31, 2009, 10:28:58 PM »
If you don't want to bother learning PWM, there are more expensive motor drivers than can accept serial data instead.

For example, my Axon can communicate with the dimensionengineering.com motor drivers through simple serial commands.

Offline Trumpkin

  • Supreme Robot
  • *****
  • Posts: 1,176
  • Helpful? 5
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #3 on: April 02, 2009, 08:54:10 AM »
Or you don't have to mess around with PWM at all and just have the motor go on or off, if the motor is slow enough.
Robots are awesome!

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #4 on: April 02, 2009, 08:42:26 PM »
Its not in an on and off process, my instructor wanted me to make a program which control's the motor control from the axon microcontroller... for instance if I store a program to turn on motor then move forward in clockwise in short telling the motor control an instruction via programmed axon microcontroller... by the way thanks for your reply mates... I really appreciate it

Offline Trumpkin

  • Supreme Robot
  • *****
  • Posts: 1,176
  • Helpful? 5
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #5 on: April 03, 2009, 08:11:21 AM »
Actually you can do all that you have specified by turning the motor on and off (no speed control). Assuming your motor doesn't draw more than 1 amp I would recommend you get an SN754410 http://www.sparkfun.com/commerce/product_info.php?products_id=315  and then just tie the enable pins to vcc and switch the inputs high and low using the axon (or any other microcontroller). You can then control direction but not speed, unless you want to do software PWM.
« Last Edit: April 03, 2009, 08:23:25 AM by Trumpkin »
Robots are awesome!

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #6 on: April 03, 2009, 09:45:26 AM »
Unfortunately we've already brought the motor controller... do you guys have a sample for motor control script for C langauge, a script which has a capability to control the speed and direction of the motor controller...  thanks again for your complies mates :)

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
    • RazorConcepts
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #7 on: April 03, 2009, 10:15:19 AM »
All info you need is here:
http://www.robotshop.ca/PDF/kit-motor-controller-l298-solarbotics.pdf

Use the commands PORT_ON(PORTLETTER, PORTNUMBER) and PORT_OFF to turn certain pins on and off.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #8 on: April 03, 2009, 11:42:14 AM »
If you look at the L298 datasheet, it'll say exactly how to command the pins. It's scary at first, but give it a try.

Look at the Axon code, and you'll see commands for using PWM to copy/paste.

Just do your best, think about it for a bit, and give it a try. If it still doesn't work, post your code here and we'll fix it up for you.

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #9 on: April 03, 2009, 01:25:04 PM »
Thanks, Admin... :) I'll post the results after the results

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #10 on: April 24, 2009, 05:34:25 AM »
Good Morning, I follow what you said... but I've got an error and need your help...
the error is the following:
-------- begin --------

Cleaning project:
rm -f cat_toy.hex
rm -f cat_toy.eep
rm -f cat_toy.obj
rm -f cat_toy.cof
rm -f cat_toy.elf
rm -f cat_toy.map
rm -f cat_toy.obj
rm -f cat_toy.a90
rm -f cat_toy.sym
rm -f cat_toy.lnk
rm -f cat_toy.lss
rm -f a2d.o buffer.o uart4.o timerx8.o rprintf.o cat_toy.o 
rm -f  a2d.lst buffer.lst uart4.lst timerx8.lst rprintf.lst cat_toy.lst
rm -f a2d.s buffer.s uart4.s timerx8.s rprintf.s cat_toy.s
rm -f a2d.d buffer.d uart4.d timerx8.d rprintf.d cat_toy.d
rm -f .dep/*
Errors: none
-------- end --------

Build succeeded with 0 Warnings...

Compiling: Axon.c
avr-gcc -c -mmcu=atmega640 -I. -gstabs   -O0 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=Axon.lst  -std=gnu99 -Wp,-M,-MP,-MT,Axon.o,-MF,.dep/Axon.o.d Axon.c -o Axon.o
Axon.c: In function 'main':
Axon.c:57: warning: implicit declaration of function 'timer3Init'
Axon.c:58: warning: implicit declaration of function 'timer4Init'
Axon.c:64: error: 'i' undeclared (first use in this function)
Axon.c:64: error: (Each undeclared identifier is reported only once
Axon.c:64: error: for each function it appears in.)
Axon.c:75: error: 'j' undeclared (first use in this function)
Axon.c:99: warning: implicit declaration of function 'reset_timer_3'
Axon.c:100: warning: implicit declaration of function 'reset_timer_4'
Axon.c:110: warning: implicit declaration of function 'PWM_Init_timer1_LED'
Axon.c:111: warning: implicit declaration of function 'PWM_timer1_On_LED'
Axon.c:117: warning: implicit declaration of function 'PWM_timer1_Set_LED'
Axon.c:130: warning: implicit declaration of function 'PWM_Init_timer2_C0'
Axon.c:131: warning: implicit declaration of function 'PWM_Init_timer4_C0'
Axon.c:135: warning: implicit declaration of function 'PWM_timer2_On_C0'
Axon.c:136: warning: implicit declaration of function 'PWM_timer4_On_C0'
Axon.c:141: warning: implicit declaration of function 'PWM_timer2_Set_C0'
Axon.c:142: warning: implicit declaration of function 'PWM_timer4_Set_C0'
Axon.c:158: warning: implicit declaration of function 'PWM_timer2_Off_C0'
Axon.c:159: warning: implicit declaration of function 'PWM_timer4_Off_C0'
make: *** [Axon.o] Error 1
Build failed with 4 errors and 15 warnings...

Here's my code:
/****************************************************************************
*
*   Copyright (c) 2008 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.
*
****************************************************************************/

//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff
#include "hardware.c" //declare hardware variables and ports
//#include "CMUcam.c" //not yet written
#include "sensors.c" //not yet written, sensor libraries for sonar, sharp IR, etc.
//#include "Blackfin_Axon.c" //files for Blackfin Robot camera
#include "control.c" //your code goes in here
//#include "axon_test.c" //include this is doing a function test for the Axon
//#include "axon_oscope_test.c" //include this is doing a function test for the Axon


int main(void)
   {



   /****************INITIALIZATIONS*******************/
   //other stuff Im experimenting with for SoR
   uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
    uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection
    uartSetBaudRate(2, 38400); // set UARTH speed
    uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
   //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

   rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf

   timer0Init(); // initialize the timer system
   timer2Init(); // initialize the timer system
   
   configure_ports(); // configure which ports are analog, digital, etc.

   a2dInit(); // initialize analog to digital converter (ADC)
   a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
   a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

   LED_on();

    // initialize the timer system (comment out ones you don't want)
   timer0Init();
   timer1Init();
   timer2Init();
   timer3Init();
   timer4Init();
    //timer5Init ();

   //rprintf("\r\nSystem Warming Up");

   //let system stabelize for X time
   for(i=0;i<=16;i++)
      {
      delay_cycles(5000);
      rprintf(".");
      }

   delay_cycles(6000);

   //read each ADC once to get it working accurately
    for(i=0;i<16;i++)
     {
      j=a2dConvert8bit(i);//read each ADC once to get it working accurately
      delay_cycles(5000); //keep LED on long enough to see Axon reseting
      rprintf(".");
     }

   LED_off();
   /**************************************************/

//test programs
//while(1)
//{
//test_oscope();
//test();
//}
   
   /*********ADD YOUR CODE BELOW THIS LINE **********/

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

   //wait until user pushes button
   while(!button_pressed());

   reset_timer_0();
   reset_timer_2();
    reset_timer_3();
   reset_timer_4();
   //reset_timer_5();
   
   
   while(1)
      {
      control();//use this for your code

         //servo_controller();

         PWM_Init_timer1_LED(8);
         PWM_timer1_On_LED();

             while(1)
                    {
                      for(i=90;i<255;i++)
                       {
                         PWM_timer1_Set_LED(i);
                         delay_ms(10);
                       }
                     for(i=255;i>90;i--)
                       {
                        PWM_timer1_Set_LED(i);
                                 delay_ms(10);
                       }
      
                     }
           
               //Initializing timer2 for PWM
                  PWM_Init_timer1_LED(8);
            PWM_Init_timer2_C0(10);//9 doesn't work
         PWM_Init_timer4_C0(10);

         //Turning "ON" both PWM channels
           //PWM_timer1_On_LED();
            PWM_timer2_On_C0();
            PWM_timer4_On_C0();
                delay_ms(1000);

            //Setting the PWM duty cycler or speed 01% - 49%
              //PWM_timer1_Set_LED(1);
            PWM_timer2_Set_C0(1);
            PWM_timer4_Set_C0(1);
                  delay_ms(1000);

            //Setting the PWM to 50% - 98% duty cycler or speed
              //PWM_timer1_Set_LED(127);
            PWM_timer2_Set_C0(127);
            PWM_timer4_Set_C0(127);
                    delay_ms(1000);

            //Setting the PWM to 99% - 100% duty cycler or full speed
              //PWM_timer1_Set_LED(254);
            PWM_timer2_Set_C0(254);
            PWM_timer4_Set_C0(254);
                    delay_ms(1000);

            //Turning "OFF" both PWM channels
            PWM_timer2_Off_C0();
            PWM_timer4_Off_C0();
                 delay_ms(1000);








      delay_cycles(100);//an optional small delay to prevent crazy oscillations
      }
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

   return 0;
   }




I really need your help Admin..., I am trying to put the motor controller in only 1 port in C0 to my axon. The motor controller is composed of Y-cable...
and here's the sample code that written in Stamp 2 from solarbotics the manufacturer of the motor controller:

'{$STAMP BS2}
'Sample Code for the Parallax BS2 using the
'Solarbotics CMD Motor driver
'Rev 1.0
'(c) Solarbotics Ltd., 2006
'by Dan Gates June 12 2006

'----------------------------- Program Description -------------------------

' This CMD Sample program is for testing your CMD motor driver with a Basic
' Stamp2 or compatable.
' First we declare the motor connection pins in the "Pin Allocation category
' and create a temp register for good measure.
' Then in MAIN we turn OFF both motor enable lines for about 1 second and
' Proceed to turn each motor on in the following sequence as if they were
' driving a robot:
' Forward, Backward, LEFT, and RIGHT each for a brief period of time (about
' two and a half seconds).
' A last we jump back to the beginning of the code and start over in a never
' ending loop.
'
' This program assumes that you connect the CMD to the following BS2 pins;
' Pin7 = E 1-2
' Pin8 = E 3-4
' Pin9 = L1
' Pin10= L2
' Pin11= L3
' Pin12= L4
' Be sure to connect at least 6v to the power input and connect the motors
' to the outputs.


'----------------------------- Pin Allocations -----------------------------

'Motor control
Enable_Right        CON 7        'Enable high, disable low
Enable_Left         CON 8        'Enable high, disable low

                             '------------ Direction Truth Table -------------
                             'L1 & L3 | L2 & L4 | M1,M2,M3,M4 Outputs
                             '--------|---------|-----------------------------
M1a_Direction       CON 9     '  HIGH  |   HIGH  | Outputs = High (Motor Break)
M1b_Direction       CON 10    '  LOW   |   LOW   | Outputs = LOW  (Motor Coast)
M2a_Direction       CON 11    '  HIGH  |   LOW   | Current flows POS.(Direction 1)
M2b_Direction       CON 12    '  LOW   |   HIGH  | Current flows Neg.(Direction 2)
                             '------------------------------------------------


Temp                VAR Word      'Temp register for manipulating bits

'------------------------------ Start of main program ---------------------
MAIN:
   LOW Enable_Right               'Turn off Right Motor
   LOW Enable_Left                'Turn off Left Motor
   PAUSE 400                      'Wait 1 second
   GOSUB FORWARD                  'Jump to Forward Subroutine
   PAUSE 1000                     'Do it for 2.5 seconds
   GOSUB BACKWARD                 'Jump to Backward Subroutine
   PAUSE 1000                     'Do it for 2.5 seconds
   GOSUB LEFT                     'Jump to Left Subroutine
   PAUSE 1000                     'Do it for 2.5 seconds
   GOSUB RIGHT                    'Jump to right subroutine
   PAUSE 1000                     'Do it for 2.5 seconds

GOTO MAIN                         'Go back and start again

'----------------------------- Subroutines ---------------------------------
FORWARD:
   HIGH Enable_Right              'Turn on right motor
   HIGH Enable_Left               'Turn on left motor
   HIGH M1a_Direction             'This comination makes the right
   LOW M1b_Direction              'motor turn clockwise
   HIGH M2a_Direction             'This combination makes the left
   LOW M2b_Direction              'motor turn Counterclockwise
RETURN                            'return from this subroutine to the main
                                  'program

BACKWARD:
   HIGH Enable_Right              'Make sure motors are still on
   HIGH Enable_Left
   LOW M1a_Direction              'This combination makes the right motor
   HIGH M1b_Direction             'turn counterclockwise
   LOW M2a_Direction              'This combination makes the left motor
   HIGH M2b_Direction             'turn clockwise
RETURN

LEFT:
   HIGH Enable_Right              'Make sure motors are still on
   HIGH Enable_Left
   LOW M1a_Direction              'This combination makes the right motor
   HIGH M1b_Direction             'turn counterclockwise
   HIGH M2a_Direction             'This combination makes the left motor
   LOW M2b_Direction              'turn counterclockwise
RETURN

RIGHT:
   HIGH Enable_Right             'Make sure motors are still on
   HIGH Enable_Left              'This combination makes the right motor
   HIGH M1a_Direction            'turn clockwise
   LOW M1b_Direction             'This combination makes the left motor
   LOW M2a_Direction             'turn clockwise
   HIGH M2b_Direction
RETURN

GOTO main                        'We should never reach this point, but
                                 'it's a good failsafe

'--------------------------------------------------------------------------------
' Now it's your turn to play around with this code and see if you can make it do
' other cool stuff. Try using the "Break" mode to stop the motors between direction
' changes.
'---------------------------------------------------------------------------------

Do you think, there's any way I can convert this script to C language that can synchronize to axon and the L298 motor controller...? please help  ???

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #11 on: April 24, 2009, 08:16:22 AM »
Those PWM features are only available with the latest code release. You'll need to swap to it.

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #12 on: April 24, 2009, 01:49:06 PM »
you mean, I have to use the old version...?

Offline Trumpkin

  • Supreme Robot
  • *****
  • Posts: 1,176
  • Helpful? 5
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #13 on: April 24, 2009, 01:53:22 PM »
You have to use the new version (the latest).
Robots are awesome!

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #14 on: April 24, 2009, 02:11:37 PM »
the current 2009 version...? I am currently using the cat toy example

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #15 on: April 24, 2009, 10:12:03 PM »
the current 2009 version...? I am currently using the cat toy example
The cat toy example used the old version.

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #16 on: May 07, 2009, 05:28:47 PM »
It seems, the code is not reacting to the motor controller..., I really need your help guys :'(
before I report to my club tomorrow and is there a way I can synchronize my motor control? (I notice from the manual's logic table: http://www.solarbotics.com/assets/datasheets/solarbotics_l298_compact_motor_driver_kit.pdf)
 
Here's my code:

/****************************************************************************
*
*   Copyright (c) 2008 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.
*
****************************************************************************/

//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff
#include "hardware.c" //declare hardware variables and ports
#include "sensors.c"    //sensor libraries for sonar, sharp IR, etc.
#include "misc.c"       //includes libraries for various hardware and other useful stuff
#include "control.c" //your code goes in here
//#include "CMUcam.c" //not yet written
//#include "axon_DAQ.c" //use the Axon like a data acquisition device
//#include "Blackfin_Axon.c" //files for Blackfin Robot camera
//#include "servo_controller.c" //Axon servo controller
//#include "axon_test.c" //include this is doing a function test for the Axon
//#include "axon_oscope_test.c" //include this is doing a function test for the Axon


int main(void)
   {
   //declare variables here
   int i=0;//useless variable
   int j=0;//useless variable


   /****************INITIALIZATIONS*******************/
   //other stuff Im experimenting with for SoR
   uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
    uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection
    uartSetBaudRate(2, 38400); // set UARTH speed
    uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
   //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

   rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf

   configure_ports(); // configure which ports are analog, digital, etc.

   LED_on();

   rprintf("\r\nSystem Warming Up");

   // initialize the timer system (comment out ones you don't want)
   timer0Init();
   timer1Init();
   timer2Init();
   timer3Init();
   timer4Init();
   //timer5Init();

   a2dInit(); // initialize analog to digital converter (ADC)
   a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
   a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

   //let system stabelize for X time
   for(i=0;i<16;i++)
      {
      j=a2dConvert8bit(i);//read each ADC once to get it working accurately
      delay_cycles(5000); //keep LED on long enough to see Axon reseting
      rprintf(".");
      }

   LED_off();
   /**************************************************/

//test programs
//while(1)
//{
//test_oscope();
//test();
//}
   
   /*********ADD YOUR CODE BELOW THIS LINE **********/

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

   //wait until user pushes button
   //while(!button_pressed());

   //reset all timers to zero
   reset_timer_0();
   reset_timer_1();
   reset_timer_2();
   reset_timer_3();
   reset_timer_4();
   //reset_timer_5();

   while(1)
      {
      //control();  //uncomment this for your code (and use control.c only to program)

      //servo_controller();

//below is various test code for Admin

PWM_Init_timer1_LED(8);
PWM_timer1_On_LED();
while(1)
   {
   for(i=90;i<255;i++)
      {
      PWM_timer1_Set_LED(i);
      delay_ms(10);
      }
   for(i=255;i>90;i--)
      {
      PWM_timer1_Set_LED(i);
      delay_ms(10);
      }
      rprintf("stuff\r\n");
   }

//rprintf("Initializing timer2 for PWM\r\n");
PWM_Init_timer1_LED(8);
PWM_Init_timer2_H6(8);//9 doesn't work
PWM_Init_timer3_E3(8);
PWM_Init_timer3_E4(8);
PWM_Init_timer3_E5(8);
delay_ms(100);
rprintf("2");
//PWM_Init_timer4_H3(10);
delay_ms(100);
rprintf("3");
//PWM_Init_timer4_H4(10);
delay_ms(100);
rprintf("4");
//PWM_Init_timer4_H5(10);
delay_ms(100);
rprintf("5");

//rprintf("Turning on both PWM channels\r\n");
PWM_timer1_On_LED();
PWM_timer2_On_();
PWM_timer3_On_C0();
PWM_timer3_On_C1();
PWM_timer4_On_C0();
PWM_timer4_On_C1();
delay_ms(1000);

//rprintf("Setting PWM to 1%% duty cycle\r\n");
PWM_timer1_Set_LED(1);
PWM_timer2_Set_C0(1);
PWM_timer3_Set_C0(1);
PWM_timer3_Set_C1(1);
PWM_timer4_Set_C0(1);
PWM_timer4_Set_C1(1);
delay_ms(2000);

//rprintf("Setting PWM to 50%% duty cycle\r\n");
PWM_timer1_Set_LED(127);
PWM_timer2_Set_C0(127);
PWM_timer3_Set_C0(127);
PWM_timer3_Set_C1(127);
PWM_timer4_Set_C0(127);
PWM_timer4_Set_C1(127);
delay_ms(3000);

rprintf("Setting PWM to 99%% duty cycle\r\n");
PWM_timer1_Set_LED(254);
PWM_timer2_Set_C0(254);
PWM_timer3_Set_C0(254);
PWM_timer3_Set_C1(254);
PWM_timer4_Set_C0(254);
PWM_timer4_Set_C1(254);
delay_ms(4000);

//rprintf("Turning off PWM\r\n");
PWM_timer1_Off_LED();
PWM_timer2_Off_C0();
PWM_timer3_Off_C0();
PWM_timer3_Off_C1();
PWM_timer4_Off_C0();
PWM_timer4_Off_C1();
delay_ms(5000);

      delay_cycles(100);//an optional small delay to prevent crazy oscillations
      }
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

   return 0;
   }

Thanks mates, I really need your help and I am not quite confident in my c programming skills than Visual Basic...

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #17 on: May 07, 2009, 06:44:39 PM »
Quote
It seems, the code is not reacting to the motor controller
What do you mean? What does your multimeter/oscilloscope say?

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #18 on: May 07, 2009, 07:09:31 PM »
When I turned it on, the two motors is running; however, I am expecting to run a few seconds (i.e. 50 sec. to a minuite), but it just check ore reset the timer while the status led is on then after a second or two the motors are off... the LED in motor control are both red... any suggestions ??? (by the way Mr. Admin, thanks a lot for your comply)

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #19 on: May 08, 2009, 12:40:20 AM »
Quote
but it just check ore reset the timer while the status led is on then after a second or two the motors are off.
I dont understand, what do you mean?

What I meant by my last post is, please check all of your circuit and battery with a multimeter first. Make sure the voltages are ok. Then check the PWM signal with an oscilloscope.

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #20 on: May 22, 2009, 11:35:42 AM »
unfortunately I didn't have an oscilloscope; however, I successfully control its speed but my advisor give me another challenge..., how I can rotate the DC counterclockwise while the other DC is clockwise rotating to turn forward backward under the water... (H3 is left while H6 is right)


here's my code:

/****************************************************************************
*
*   Copyright (c) 2008 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.
*
****************************************************************************/

//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff
#include "hardware.c" //declare hardware variables and ports
#include "sensors.c" //sensor libraries for sonar, sharp IR, etc.
#include "misc.c" //includes libraries for various hardware and other useful stuff
//#include "control.c" //your code goes in here
//#include "CMUcam.c" //not yet written
//#include "axon_DAQ.c" //use the Axon like a data acquisition device
//#include "Blackfin_Axon.c" //files for Blackfin Robot camera
//#include "servo_controller.c" //Axon servo controller
//#include "axon_test.c" //include this is doing a function test for the Axon
//#include "axon_oscope_test.c" //include this is doing a function test for the Axon


int main(void)
   {
   //declare variables here
   int i=0;//useless variable
   int j=0;//useless variable


   /****************INITIALIZATIONS*******************/
   //other stuff Im experimenting with for SoR
   uartInit();  // initialize the UART (serial port)
    uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
    uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection
    uartSetBaudRate(2, 38400); // set UARTH speed
    uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
   //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

   rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf

   configure_ports(); // configure which ports are analog, digital, etc.

   LED_on();

   rprintf("\r\nSystem Warming Up");

   // initialize the timer system (comment out ones you don't want)
   //timer0Init();
   //timer1Init();
   timer2Init();
   //timer3Init();
   timer4Init();
   //timer5Init();

   a2dInit(); // initialize analog to digital converter (ADC)
   a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
   a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

   //let system stabelize for X time
   for(i=0;i<16;i++)
      {
      j=a2dConvert8bit(i);//read each ADC once to get it working accurately
      delay_cycles(5000); //keep LED on long enough to see Axon reseting
      rprintf(".");
      }

   while(1)
      {
           //control();   //uncomment this for your code (and use control.c only to program)

      //servo_controller();
         
       //rprintf("Initializing timer2 for PWM\r\n");
PWM_Init_timer2_H6(10);
PWM_Init_timer4_H3(10);

rprintf("Turning on both PWM channels\r\n");
PWM_timer2_On_H6();
PWM_timer4_On_H3();
//delay_ms(1000);

/*
PWM_timer2_Set_H6(10);
PWM_timer4_Set_H3(10);
delay_ms(100);
*/


PWM_timer2_Set_H6(20);   /* Still on debug */
PWM_timer4_Set_H3(10);
delay_ms(2000);         


PWM_timer2_Set_H6(-254);
PWM_timer4_Set_H3(-127);
delay_ms(3000);


//rprintf("Setting PWM to 50%% duty cycle\r\n");
//PWM_timer2_Set_H6(127);
//PWM_timer4_Set_H3(127);
//delay_ms(30000);

//rprintf("Setting PWM to 99%% duty cycle\r\n");
//PWM_timer2_Set_H6(254);
//PWM_timer4_Set_H3(254);
//delay_ms(40000);

rprintf("Turning off PWM\r\n");
PWM_timer2_Off_H6();
PWM_timer4_Off_H3();
delay_ms(2000);

//below is various test code for Admin


                 

    //rprintf("Turning off PWM\r\n");
     

      delay_cycles(100);//an optional small delay to prevent crazy oscillations
      }
   
   /**************************************************/

//test programs
  //while(1)
  //{
  //test_oscope();
  //test();
  //}
   LED_off();
   /*********ADD YOUR CODE BELOW THIS LINE **********/

   
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

   return 0;
   }


please help... 

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #21 on: May 22, 2009, 12:41:59 PM »
Look at the motor driver datasheet. It'll say how to reverse the motor - you'll need to activate the correct digital pins to do this.

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #22 on: May 27, 2009, 09:27:25 PM »
Hi thanks for replying, before I tackle the counter-clockwise mode, me and the group unexpectedly encounter a new problem. We've found out that, in the template program from Axon has no conditional programming such as setting the speed from low to high then stop PWM..., I need to put a timer script and a conditional logic for sensors programming in the next few weeks... can you help me to apply conditional functions... and is the delay_ms(XX); is a timer function...?
Below is my code again...,

/****************************************************************************
*
*   Copyright (c) 2008 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.
*
****************************************************************************/

//SoR Include
#include "SoR_Utils.h" //includes all the technical stuff
#include "hardware.c" //declare hardware variables and ports
#include "sensors.c" //sensor libraries for sonar, sharp IR, etc.
#include "misc.c" //includes libraries for various hardware and other useful stuff
//#include "control.c" //your code goes in here
//#include "CMUcam.c" //not yet written
//#include "axon_DAQ.c" //use the Axon like a data acquisition device
//#include "Blackfin_Axon.c" //files for Blackfin Robot camera
//#include "servo_controller.c" //Axon servo controller
//#include "axon_test.c" //include this is doing a function test for the Axon
//#include "axon_oscope_test.c" //include this is doing a function test for the Axon


int main(void)
   {
   //declare variables here
   int i=0;//useless variable
   int j=0;//useless variable


   /****************INITIALIZATIONS*******************/
   //other stuff Im experimenting with for SoR
   uartInit();  // initialize the UART (serial port)
        uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth
        uartSetBaudRate(1, 115200); // set UARTD speed, for USB connection
        uartSetBaudRate(2, 38400); // set UARTH speed
        uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin
   //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx)

   rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf

   configure_ports(); // configure which ports are analog, digital, etc.

   LED_on();

   rprintf("\r\nSystem Warming Up");

   // initialize the timer system (comment out ones you don't want)
   //timer0Init();
   //timer1Init();
   timer2Init();
   //timer3Init();
   timer4Init();
   //timer5Init();


   a2dInit(); // initialize analog to digital converter (ADC)
   a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
   a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage


   //let system stabelize for X time
   for(i=0;i<16;i++)
      {
      j=a2dConvert8bit(i);//read each ADC once to get it working accurately
      delay_cycles(5000); //keep LED on long enough to see Axon reseting
      rprintf(".");
      }

   
   
   
   while(1)
      {
            /*******************
           control();          // <----- Uncomment this for your code (and use control.c only to program)
          servo_controller();
            *******************/


               /**Initializing timer2 for PWM**/
                  PWM_Init_timer2_H6(10);
                  PWM_Init_timer4_H3(10);

               /**Turning ON both PWM channels**/
                  PWM_timer2_On_H6();
                  PWM_timer4_On_H3();
                //delay_ms(200);

                  /***** // 1st Phase
                    PWM_timer2_Set_H6(10);
                    PWM_timer4_Set_H3(10);
                    delay_ms(100);
                  ****************************/

                     // 2nd Phase
                    PWM_timer2_Set_H6(20);   // <--------- Still on debug.
                    PWM_timer4_Set_H3(50);
                    delay_ms(10);
                 
             
              /***** // 3rd Phase
                    PWM_timer2_Set_H6(254);
                    PWM_timer4_Set_H3(127);
                    delay_ms(3000);
                  ****************************/


                  /*********************************
                //Setting PWM to 50%% duty cycle.
                    PWM_timer2_Set_H6(127);
                    PWM_timer4_Set_H3(127);
                    delay_ms(30000);
                  **********************************/

                  /*********************************                 
               //Setting PWM to 99%% duty cycle.
                    PWM_timer2_Set_H6(254);
                    PWM_timer4_Set_H3(254);
                    delay_ms(40000);
                  **********************************/

               /**Turning OFF both PWM.**/
                  PWM_timer2_Off_H6();
                  PWM_timer4_Off_H3();
                  delay_ms(10);
                 
             

       delay_cycles(100);   // <------------------------ An optional small delay to prevent crazy oscillations
      }

   LED_off();

   /**************************************************/
   
    /************** TEST PROGRAMS *****************
        while(1)
       {
        test_oscope();
        test();
       }
   ***************/

   /*********ADD YOUR CODE BELOW THIS LINE **********/

   
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

   return 0;
   }
   

Offline BANE

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #23 on: May 28, 2009, 09:03:23 PM »
Hi,

I actually have this exact motor controller and must warn you that if using PWM you wont get 100% duty cycle, please correct if i'm wrong.  I program in basic but you'll need to include a if and then statement to reverse the high or low pin as well as the PWM pin.  For example:
Code: [Select]
X = temp(5)
Y = temp(6)

if Y < 115 then
Y =  (230 - Y) * 2
low 0
pwm p1, Y, 5000
low 2
pwm p3, Y, 5000


elseif Y > 141
Y = (Y - 141) * 2
pwm p0, Y, 5000
low 1
pwm p2, Y, 5000
low 3


elseif X < 115
X = (230 - X) * 2
dydx = X/2
pwm p0, dydx, 5000
low 1
pwm p2, x, 5000
low 3


elseif X > 141
X = (X - 141) * 2
dydx = X/2
pwm p0, dydx, 5000
low 1
pwm p2, x, 5000
low 3
endif

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #24 on: May 30, 2009, 05:49:14 PM »
Thanks for replaying Bane, I tried your conditional statements; however, I encounter an error regarding:
Code: [Select]
Axon.c:166: error: 'else' without a previous 'if'
make: *** [Axon.o] Error 1


My Source Code is below...
Code: [Select]
rprintf("Initializing timer2 for PWM\r\n");
          PWM_Init_timer2_H6(10);
          delay_ms(10);        

rprintf("Initializing timer4 for PWM\r\n");
          PWM_Init_timer4_H3(20);
          delay_ms(20);


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


         rprintf("Turning on both PWM channels\r\n");        
          //Turning on both PWM channels
          PWM_timer2_On_H6();
          PWM_timer4_On_H3();
          delay_ms(325);

while(1)
{

 /************* NOTE **************
     int One=64;      // 1st Speed
        int Two=127;      // 2nd Speed
         int Three=254;      // 3rd Speed
           ********************************/
          
       One=64;        // 1st Speed
               Two=127;        // 2nd Speed
    Three=254;        // 3rd Speed

            if (One == Two && One++)
                 rprintf("Setting PWM to 1%% duty cycle\r\n");
                          PWM_timer2_Set_H6(One);
                          PWM_timer4_Set_H3(One);
                                 delay_ms(200);
   else if (One == 0 && One--)
          rprintf("Turning off PWM\r\n");
            else                              
                         PWM_timer2_Off_H6();
                                          PWM_timer4_Off_H3();
                                                 delay_ms(20);  
 
 
 /*************************************************
else if (Two > Three)
             (Two = (Three - Two) * 2);
                            PWM_timer2_Set_H6(Two);
   PWM_timer4_Set_H3(Two);
   delay_ms(100);

                  else if (Three                            
    PWM_timer2_Off_H6();
                        PWM_timer4_Off_H3();
  **************************************************/  
 
    delay_cycles(100);//an optional small delay to prevent crazy oscillations
       
}
        
            //reset all timers to zero
         reset_timer_2();
         reset_timer_4();

Thanks mate...
 
« Last Edit: May 30, 2009, 05:51:26 PM by johncban »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #25 on: May 30, 2009, 06:39:12 PM »
Quote
error: 'else' without a previous 'if'
That means you are calling an else statement without a preceding if statement.

In your code I see several 'else if' statements without a preceding if statement. ;D

Offline johncbanTopic starter

  • Jr. Member
  • **
  • Posts: 22
  • Helpful? 0
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #26 on: May 31, 2009, 07:05:40 PM »
Thanks Mr. Admin  :), now I am in pace I rather use switch statement than if else because I am having a hard time to transfer the speed level from 1 to 256 PWM; however, switch statement seems promising. Currently change the power wiring of my two DC motors to make it counterclockwise (Forward throttle in water), now I seriously wanted clockwise mode (Backward throttle in water)...

I saw a script (under Basic) from Solarbotics Website... (below)


Code: [Select]
'{$STAMP BS2}
'Sample Code for the Parallax BS2 using the
'Solarbotics CMD Motor driver
'Rev 1.0
'(c) Solarbotics Ltd., 2006
'by Dan Gates June 12 2006

'----------------------------- Program Description -------------------------

' This CMD Sample program is for testing your CMD motor driver with a Basic
' Stamp2 or compatable.
' First we declare the motor connection pins in the "Pin Allocation category
' and create a temp register for good measure.
' Then in MAIN we turn OFF both motor enable lines for about 1 second and
' Proceed to turn each motor on in the following sequence as if they were
' driving a robot:
' Forward, Backward, LEFT, and RIGHT each for a brief period of time (about
' two and a half seconds).
' A last we jump back to the beginning of the code and start over in a never
' ending loop.
'
' This program assumes that you connect the CMD to the following BS2 pins;
' Pin7 = E 1-2
' Pin8 = E 3-4
' Pin9 = L1
' Pin10= L2
' Pin11= L3
' Pin12= L4
' Be sure to connect at least 6v to the power input and connect the motors
' to the outputs.


'----------------------------- Pin Allocations -----------------------------

'Motor control
Enable_Right        CON 7        'Enable high, disable low
Enable_Left         CON 8        'Enable high, disable low

                             '------------ Direction Truth Table -------------
                             'L1 & L3 | L2 & L4 | M1,M2,M3,M4 Outputs
                             '--------|---------|-----------------------------
M1a_Direction       CON 9     '  HIGH  |   HIGH  | Outputs = High (Motor Break)
M1b_Direction       CON 10    '  LOW   |   LOW   | Outputs = LOW  (Motor Coast)
M2a_Direction       CON 11    '  HIGH  |   LOW   | Current flows POS.(Direction 1)
M2b_Direction       CON 12    '  LOW   |   HIGH  | Current flows Neg.(Direction 2)
                             '------------------------------------------------


Temp                VAR Word      'Temp register for manipulating bits

'------------------------------ Start of main program ---------------------
MAIN:
   LOW Enable_Right               'Turn off Right Motor
   LOW Enable_Left                'Turn off Left Motor
   PAUSE 400                      'Wait 1 second
   GOSUB FORWARD                  'Jump to Forward Subroutine
   PAUSE 1000                     'Do it for 2.5 seconds
   GOSUB BACKWARD                 'Jump to Backward Subroutine
   PAUSE 1000                     'Do it for 2.5 seconds
   GOSUB LEFT                     'Jump to Left Subroutine
   PAUSE 1000                     'Do it for 2.5 seconds
   GOSUB RIGHT                    'Jump to right subroutine
   PAUSE 1000                     'Do it for 2.5 seconds

GOTO MAIN                         'Go back and start again

'----------------------------- Subroutines ---------------------------------
FORWARD:
   HIGH Enable_Right              'Turn on right motor
   HIGH Enable_Left               'Turn on left motor
   HIGH M1a_Direction             'This comination makes the right
   LOW M1b_Direction              'motor turn clockwise
   HIGH M2a_Direction             'This combination makes the left
   LOW M2b_Direction              'motor turn Counterclockwise
RETURN                            'return from this subroutine to the main
                                  'program

BACKWARD:
   HIGH Enable_Right              'Make sure motors are still on
   HIGH Enable_Left
   LOW M1a_Direction              'This combination makes the right motor
   HIGH M1b_Direction             'turn counterclockwise
   LOW M2a_Direction              'This combination makes the left motor
   HIGH M2b_Direction             'turn clockwise
RETURN

LEFT:
   HIGH Enable_Right              'Make sure motors are still on
   HIGH Enable_Left
   LOW M1a_Direction              'This combination makes the right motor
   HIGH M1b_Direction             'turn counterclockwise
   HIGH M2a_Direction             'This combination makes the left motor
   LOW M2b_Direction              'turn counterclockwise
RETURN

RIGHT:
   HIGH Enable_Right             'Make sure motors are still on
   HIGH Enable_Left              'This combination makes the right motor
   HIGH M1a_Direction            'turn clockwise
   LOW M1b_Direction             'This combination makes the left motor
   LOW M2a_Direction             'turn clockwise
   HIGH M2b_Direction
RETURN

GOTO main                        'We should never reach this point, but
                                 'it's a good failsafe

'--------------------------------------------------------------------------------
' Now it's your turn to play around with this code and see if you can make it do
' other cool stuff. Try using the "Break" mode to stop the motors between direction
' changes.
'---------------------------------------------------------------------------------


Can you guys can help me translate this to C language..., I also read the header files from Axon(January 2009 source code) timer640.h. I noticed, the PWM_H6 and PWM_H3 is void... I almost tempted to touch it; however, again I am afraid to mess up the code...
Please help... I am really quite an amateur on this, all i know is to program computer apps not autonomous programming for machine and I really need to learn from you guys and have an experience for our robotics club...  

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: How to write or register a motor controller in sor_util.h of axon???
« Reply #27 on: June 04, 2009, 06:51:10 PM »
Quote
I almost tempted to touch it; however, again I am afraid to mess up the code...
Don't worry, if it doesn't work, you can just redownload it anytime.

Have a look here and see if it makes more sense:
http://www.societyofrobots.com/robotforum/index.php?topic=5590.0

 


Get Your Ad Here

data_list