Need some help in Programming

The place to discuss the Pololu 3pi robot and share your code.

Need some help in Programming

Postby bidisha.roy on Sat May 29, 2010 7:45 am

Sir, I have a 3pi Robot and have attached a CC2500 module on it. Now, I have initialized the transceiver module attached to my Desktop with the Hyper terminal
as
Self address= 2
Remote address= 1 (address of the remote device i.e. address of transceiver connected on 3pi)
Channel as= 3 (selecting channel frequency over which device wants to communicate).

Now i have to do the same on the 3pi and program the atmega328p as follows:-
Self address= 1
Remote address= 2 (address of the remote device i.e. address of transceiver connected on Desktop)
Channel as= 3 (selecting channel frequency over which device wants to communicate).
Now i see that 3pi has a inbuilt function to set the baud rate
Code: Select all
   serial_set_baud_rate(115200);
.
My Question is is there any such functions to set up the above mentioned parameters?
Code: Select all
   serial_set_mode(SERIAL_CHECK);
   serial_receive_ring(buffer, 100);

Moreover i want to know what these two functions signify can how can i change the modes.
I wrote a program in avr studio .The code is as follows
Code: Select all
void TX (unsigned char data)
{
UDR=data;
while(!UCSRA&(1<<UDRE)));
}
int main(void)
{
serial_set_baud_rate(38400);
sei;
TX('1');
TX('2');
TX('3');
while(1)
{
}
return 0;
}
Thinking if there is some functions like the baud rate then can the code snippet be optimised
bidisha.roy
 
Posts: 6
Joined: Sat May 29, 2010 6:55 am

Re: Need some help in Programming

Postby paul on Sat May 29, 2010 8:53 am

Hello,

If you are using the same module as the one in this thread, then it sounds like all you need to do is send those parameters as the first three bytes of your serial communication. So really, all you are asking is how to send bytes on the serial line.

We have very detailed information about all of the serial functions we provide here and examples here. Have you read over all of this information? For example, our serial_send() function is an advanced alternative to running your TX() function several times. To send bytes '1', '2', and '3', you can just do

Code: Select all
serial_send("123",3);


and the bytes will be sent in the background, using interrupts.

-Paul
User avatar
paul
Site Admin
 
Posts: 916
Joined: Sun Nov 30, 2003 12:06 am
Location: Las Vegas, NV

Re: Need some help in Programming

Postby paul on Sat May 29, 2010 9:02 am

By the way, you should make sure that you understand that the byte '1' is different from the byte 1 (which could also be written 0x01). If that is not clear to you, google for something like "ascii decimal in c".

If you want to use serial_send to send the bytes 1, 2, and 3, you can do this:

Code: Select all
serial_send("\x01\x02\x03",3);

-Paul
User avatar
paul
Site Admin
 
Posts: 916
Joined: Sun Nov 30, 2003 12:06 am
Location: Las Vegas, NV

Re: Need some help in Programming

Postby ken58w@yahoo.com on Tue Jun 01, 2010 3:18 pm

http://msdn.microsoft.com/en-us/library/bb466258.aspx
may help
ken58w@yahoo.com
 
Posts: 7
Joined: Wed May 19, 2010 2:28 pm

Re: Need some help in Programming

Postby ken58w@yahoo.com on Tue Jun 01, 2010 3:19 pm

http://www.microsoft.com/robotics/#GetIt
ken58w@yahoo.com
 
Posts: 7
Joined: Wed May 19, 2010 2:28 pm

Re: Need some help in Programming

Postby ken58w@yahoo.com on Tue Jun 01, 2010 3:32 pm

free software open code
http://www.abotics.com/cdbot_robot_software.htm
ken58w@yahoo.com
 
Posts: 7
Joined: Wed May 19, 2010 2:28 pm

Re: Need some help in Programming

Postby DavidEGrayson on Tue Jun 01, 2010 10:17 pm

Anyone trying to program a 3pi should disregard the links in the last three posts from ken58w.

According to this post you can't use Microsoft Robotics Studio to program an AVR. The page about the NewCDBot programming software makes it clear that the software is for programming a specific kind of robot that is not AVR-based.

--David
DavidEGrayson
Site Admin
 
Posts: 311
Joined: Thu Apr 03, 2008 12:30 pm
Location: Las Vegas, Nevada

Re: Need some help in Programming

Postby bidisha.roy on Thu Jun 17, 2010 6:37 am

Sir, I just need help in understanding this Part of the serial slave code
Code: Select all
      case (char)0xC1:
         m1_forward();
         break;
      case (char)0xC2:
         m1_backward();
         break;
      case (char)0xC5:
         m2_forward();
         break;
      case (char)0xC6:
         m2_backward();
         break;

I just Want to ask that which character does 0xC1 denote...please tell me :-D, i googled in and found that 0xC1 in EBCDIC it denoted 'A' but i want to know what does it denote in ascii, rather after burning the code in our 3pi which letter in the keyboard do we need to press
bidisha.roy
 
Posts: 6
Joined: Sat May 29, 2010 6:55 am

Re: Need some help in Programming

Postby bidisha.roy on Thu Jun 17, 2010 7:00 am

Sir, using the serial1 program in the library i developed this program but i cant understand why it is yielding 5 errors
Code: Select all
#include <pololu/orangutan.h>

char recieve_buffer[32];
char send_buffer[32];
int motorSpeed = 200;

void wait_for_sending_to_finish()
{
   while(!serial_send_buffer_empty());
}

void process_received_byte(char byte)
{
   switch(byte)
   {
      
      case 'w':
         set_motors(motorSpeed, motorSpeed);
         break;

      
      case 's':
         set_motors(-motorSpeed, -motorSpeed);
         break;


      case 'a':
         set_m1_speed(motorSpeed);
         break;


      case 'd':
         set_m2_speed(motorSpeed);
         break;

      default:
         wait_for_sending_to_finish();
         send_buffer[0] = byte ^ 0x20;
         serial_send(send_buffer, 1);
         break;
   }
}

void check_for_new_bytes_received()
{
   while(serial_get_received_bytes() != receive_buffer_position)
   {
   
      process_received_byte(receive_buffer[receive_buffer_position]);

      if (receive_buffer_position == sizeof(receive_buffer)-1)
      {
         receive_buffer_position = 0;
      }
      else
      {
         receive_buffer_position++;
      }
   }
}

int main()
{
   
   serial_set_baud_rate(38400);
   serial_receive_ring(receive_buffer, sizeof(receive_buffer));
   serial_send("\x01\x02\x03",3);
     
    while(1)
    {
      check_for_new_bytes_received();
      if (button_is_pressed(MIDDLE_BUTTON))
      {
         wait_for_sending_to_finish();
         memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
         serial_send(send_buffer, 11);
         wait_for_button_release(MIDDLE_BUTTON);
      }
    }
}

Sir, please tell me Where i am doing the mistake, i cant get it any how.please help me out Sir
bidisha.roy
 
Posts: 6
Joined: Sat May 29, 2010 6:55 am

Re: Need some help in Programming

Postby bidisha.roy on Thu Jun 17, 2010 7:09 am

sorry for the above code, i just found out the error, but still it is not compiling, i dont know why
Code: Select all
#include <pololu/orangutan.h>

char recieve_buffer[32];
char send_buffer[32];
unsigned char receive_buffer_position = 0;
int motorSpeed = 200;

void wait_for_sending_to_finish()
{
   while(!serial_send_buffer_empty());
}

void process_received_byte(char byte)
{
   switch(byte)
   {
      
      case 'w':
         set_motors(motorSpeed, motorSpeed);
         break;

      
      case 's':
         set_motors(-motorSpeed, -motorSpeed);
         break;


      case 'a':
         set_m1_speed(motorSpeed);
         break;


      case 'd':
         set_m2_speed(motorSpeed);
         break;

      default:
         wait_for_sending_to_finish();
         send_buffer[0] = byte ^ 0x20;
         serial_send(send_buffer, 1);
         break;
   }
}

void check_for_new_bytes_received()
{
   while(serial_get_received_bytes() != receive_buffer_position)
   {
   
      process_received_byte(receive_buffer[receive_buffer_position]);

      if (receive_buffer_position == sizeof(receive_buffer)-1)
      {
         receive_buffer_position = 0;
      }
      else
      {
         receive_buffer_position++;
      }
   }
}

int main()
{
   
   serial_set_baud_rate(38400);
   serial_receive_ring(receive_buffer, sizeof(receive_buffer));
   serial_send("\x01\x02\x03",3);
     
    while(1)
    {
      check_for_new_bytes_received();
      if (button_is_pressed(MIDDLE_BUTTON))
      {
         wait_for_sending_to_finish();
         memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
         serial_send(send_buffer, 11);
         wait_for_button_release(MIDDLE_BUTTON);
      }
    }
}
bidisha.roy
 
Posts: 6
Joined: Sat May 29, 2010 6:55 am

Re: Need some help in Programming

Postby bidisha.roy on Thu Jun 17, 2010 9:29 am

In my earlier codes there are a few compilation errors which may result because i made a few changes in your example program, But when i just copy paste the same Serial1 program for serial communication(link to the example program is http://www.pololu.com/docs/0J20/6.j) just changing the Case statement to the control the motors it complies nicely but when i build the same it gives me 9 errors
the code is
Code: Select all
#include <pololu/orangutan.h> 
 
char receive_buffer[32];
unsigned char receive_buffer_position = 0;
char send_buffer[32];


void wait_for_sending_to_finish()
{
   while(!serial_send_buffer_empty());
}


void process_received_byte(char byte)
{
   switch(byte)
   {

      case 'w':
         set_motors(200,200);
         break;


      case 's':
         set_motors(-200,-200);
         break;

   
      case 'a':
         set_motors(0,200);
         break;


      case 'd':
         set_motors(200,0);
         break;


      default:
         wait_for_sending_to_finish();
         send_buffer[0] = byte ^ 0x20;
         serial_send(send_buffer, 1);
         break;
   }
}

void check_for_new_bytes_received()
{
   while(serial_get_received_bytes() != receive_buffer_position)
   {
   
      process_received_byte(receive_buffer[receive_buffer_position]);


      if (receive_buffer_position == sizeof(receive_buffer)-1)
      {
         receive_buffer_position = 0;
      }
      else
      {
         receive_buffer_position++;
      }
   }
}

int main()
{

   serial_set_baud_rate(9600);


   serial_receive_ring(receive_buffer, sizeof(receive_buffer));

    while(1)
    {

      check_for_new_bytes_received();

   
      if (button_is_pressed(MIDDLE_BUTTON))
      {
         wait_for_sending_to_finish();
         memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
         serial_send(send_buffer, 11);

      
         wait_for_button_release(MIDDLE_BUTTON);
      }
    }
}

errors are
Code: Select all
Build started 17.6.2010 at 21:52:01
avr-gcc -mmcu=atmega328p -Wl,-Map=cc2500test.map cc2500test.o     -o cc2500test.elf
cc2500test.o: In function `wait_for_sending_to_finish':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:10: undefined reference to `serial_send_buffer_empty'
cc2500test.o: In function `process_received_byte':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:35: undefined reference to `set_motors'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:42: undefined reference to `serial_send'
cc2500test.o: In function `check_for_new_bytes_received':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:49: undefined reference to `serial_get_received_bytes'
cc2500test.o: In function `main':
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:69: undefined reference to `serial_set_baud_rate'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:72: undefined reference to `serial_receive_ring'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:80: undefined reference to `button_is_pressed'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:84: undefined reference to `serial_send'
D:\Robotics\libpololu-avr\examples\atmega328p\cc2500test\default/../cc2500test.c:87: undefined reference to `wait_for_button_release'
make: *** [cc2500test.elf] Error 1
Build failed with 9 errors and 0 warnings...

Sir please help me out, i dont understand what is happening
bidisha.roy
 
Posts: 6
Joined: Sat May 29, 2010 6:55 am

Re: Need some help in Programming

Postby DavidEGrayson on Thu Jun 17, 2010 9:58 am

bidisha.roy wrote:
Code: Select all
avr-gcc -mmcu=atmega328p -Wl,-Map=cc2500test.map cc2500test.o     -o cc2500test.elf



The linker can't find any of the functions you are trying to call because you didn't tell it to use our library. Please read this for information on how to configure AVR Studio (if that's what you are using):

Using the Pololu AVR Library for your own projects
http://www.pololu.com/docs/0J20/7

--David
DavidEGrayson
Site Admin
 
Posts: 311
Joined: Thu Apr 03, 2008 12:30 pm
Location: Las Vegas, Nevada

Re: Need some help in Programming

Postby bidisha.roy on Thu Jun 17, 2010 10:36 am

Thank you very much sir, everything is running just fine
bidisha.roy
 
Posts: 6
Joined: Sat May 29, 2010 6:55 am


Return to 3pi Robot

Who is online

Users browsing this forum: No registered users and 3 guests