www.robowars.org

RoboWars Australia Forum Index -> General Chatter

Towards Autonomous Combat
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next

Post new topic   Reply to topic
  Author    Thread
bytraper



Joined: 31 Oct 2005
Posts: 195


 Reply with quote  

That's just incredible...

Post Fri Jun 17, 2011 4:45 pm 
 View user's profile Send private message MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Still thinking about this but thought I should take some more concrete steps to getting something up and running.

So my first step is to finish off my computer - > radio interface. This is not a difficult problem it just basically means being able to send serial commands to a microcontroller which then generates a PPM signal.

Current state of this was a proof of concept hack which really didn't work very well. Once I get it finished off will post code here.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Sat Jul 16, 2011 5:09 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Well got it working. There is still some issue with sending data to the microcontroller. It could be my very very basic code on the micro or more likely I think it is how python handles writing data to USB.

Here is codes through.

AVR - Teensy

code:

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <stdint.h>
#include <util/delay.h>
#include "usb_serial.h"

const float down=0.6;
const float max = 1.4/255;
const float min = 0.4;

#define debug 0

#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define CPU_16MHz       0x00
#define CPU_8MHz        0x01
#define CPU_4MHz        0x02
#define CPU_2MHz        0x03
#define CPU_1MHz        0x04
#define CPU_500kHz      0x05
#define CPU_250kHz      0x06
#define CPU_125kHz      0x07
#define CPU_62kHz       0x08


int main(void)
{
    CPU_PRESCALE(CPU_16MHz);
    DDRD |= (1<<6); //Set PORTD Pin 6 to output.
   
    PORTD |= (1<<6);  //Set High Initially
    _delay_ms(10);    //Startup Delay
   
    int time[6] = {128,128,128,128,128,128};
   
   short stage = -1;
   short channel = 0;
   short value = 0;
   usb_init();
   usb_serial_flush_input();
   
    while(1)    //Infinite Loop of
    {
        for(int i =0; i < 6; i++)
   {
      PORTD &= ~(1<<6);
      _delay_ms(down); //Lead Pulse
      PORTD |= (1<<6);
      _delay_ms( (double) time[i] *max +min); //Time1
       
        }
        PORTD &= ~(1<<6);
        _delay_ms(down); //Pause
       
        PORTD |= (1<<6);
        _delay_ms(22);
      
      if (usb_serial_available() > 0)
      {
         char r = usb_serial_getchar();
         if (r == '#')
         {
            stage = 0;
            if(debug)
            {
               usb_serial_putchar('$');
            }
         }
         else if (stage == 0 && r <= '6' && r > '0')
         {
            channel = r - '1';
            stage = 1;
            if(debug)
            {
               usb_serial_putchar('%');
               usb_serial_putchar(r);
            }
         }
         else if (stage == 1 && r == '&')
         {
            stage = 2;
            if(debug)
            {
               usb_serial_putchar('2');
            }
         }
         else if (stage == 2)
         {
            value = r;
            stage = -1;
            time[channel]=value;
            if(debug)
            {
               usb_serial_putchar('~');
               int x = value/100;
               usb_serial_putchar(x + '0');
               x = (value - x*100)/10;
               usb_serial_putchar(x+'0');
               x = (value - x*10);
               usb_serial_putchar(x+'0');
            }
            
         }
      }      
      }
}




Even simply PyGame controller
code:

#!/usr/bin/env python
import pygame
from pygame.locals import *

import time, serial

ch1mid = 85
ch2mid = 60
ch1low = 50
ch2low = 100
ch1high = 130
ch2high = 20
       
if __name__ == '__main__':
    try:
        # Initilise pygame
   pygame.init()
   screen = pygame.display.set_mode((100, 100))
   pygame.display.set_caption('rcController')
   pygame.mouse.set_visible(0)

        port = serial.Serial('/dev/ttyACM0',115200,xonxoff=True, rtscts=True, dsrdtr=True)     

        ch1 = ch1mid;
        ch2 = ch2mid;

   done = False

   while not done:
       for event in pygame.event.get():
      if event.type == KEYUP:
          if (event.key == K_UP or event.key == K_DOWN):
         ch1 = ch1mid
         ch2 = ch2mid
                        port.write('#1&'+chr(ch1)+'#2&'+chr(ch2))
                        port.flush()
          if (event.key == K_LEFT or event.key == K_RIGHT):
         ch1 = ch1mid
                        ch2 = ch2mid
                        port.write('#1&'+chr(ch1)+'#2&'+chr(ch2))
                        port.flush()
      if event.type == KEYDOWN:
          if (event.key == K_UP):
         ch1 = ch1high
         ch2 = ch2high
                        port.write('#1&'+chr(ch1)+'#2&'+chr(ch2))
                        port.flush()
          elif (event.key == K_DOWN):
         ch1 = ch1low
         ch2 = ch2low
                        port.write('#1&'+chr(ch1)+'#2&'+chr(ch2))
                        port.flush()
          elif (event.key == K_LEFT):
         ch1 = ch1low
         ch2 = ch2high
                        port.write('#1&'+chr(ch1)+'#2&'+chr(ch2))
                        port.flush()
          elif (event.key == K_RIGHT):
                        ch1 = ch1high
                        ch2 = ch2low
                        port.write('#1&'+chr(ch1)+'#2&'+chr(ch2))
                        port.flush()
          elif (event.key == K_ESCAPE):
         done = True
            time.sleep(0.1)         
       print ch1, ch2
    except KeyboardInterrupt: pass





Youtube vid is uploading
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Sat Jul 16, 2011 11:13 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

http://www.youtube.com/watch?v=vTnn5BijmA8

Now need to learn a decent way of getting Keyboard inputs in C/C++ in linux. Then will try a C/C++ driver.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Sat Jul 16, 2011 11:34 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

If there was code police I might be shot for this terrible example of coding. But here is a joystick -> USB interface.

My lag was cause by an if statement instead of a while statement when reading in data. Works much better even with python code after that was replaced.

code:

//Code based on unknown source from the internets...


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>

#include <linux/joystick.h>
#include <cereal_port/CerealPort.h>

#define MAX_AXIS 16
#define MAX_BUTTON 16

const int ch1low = 50;
const int ch2low = 100;
const int ch1high = 130;
const int ch2high = 20;

struct padData {
    unsigned char axisCount;
    unsigned char buttonCount;
    int fd;
    int version;
    char devName[80];
    int aPos[MAX_AXIS];
    int bPos[MAX_BUTTON];
    bool changed;
    js_event ev;
};

padData pad;


int main (void)
{
    bool cereal_open = true;
    cereal::CerealPort serial_port;
    pad.fd = open("/dev/input/js0", O_RDONLY);
   
    if (pad.fd > 0)
    {
        printf ("js0 opened OK\n");

        std::string output;
       
        // Get pad info ...
        ioctl(pad.fd, JSIOCGAXES, &pad.axisCount);
        ioctl(pad.fd, JSIOCGBUTTONS, &pad.buttonCount);
        ioctl(pad.fd, JSIOCGVERSION, &pad.version);
        ioctl(pad.fd, JSIOCGNAME(80), &pad.devName);
        fcntl(pad.fd, F_SETFL, O_NONBLOCK);

        printf ("axis : %d\n", pad.axisCount);
        printf ("buttons : %d\n", pad.buttonCount);
        printf ("version : %d\n", pad.version);
        printf ("name : %s\n", pad.devName);

        // set default values
        pad.changed = false;
        for (int i=0;i<pad.axisCount;i++) pad.aPos[i]=0;
        for (int i=0;i<pad.buttonCount;i++) pad.bPos[i]=0;

        try{ serial_port.open("/dev/ttyACM0",115200);}
        catch (cereal::Exception& e){
            std::cout << "Failed to open USB port" << std::endl;
            cereal_open = false;
        }
        std::cout << "connected" << std::endl;
        while(cereal_open)
        {
            int result = read(pad.fd, &pad.ev, sizeof(pad.ev));
            while (result > 0)
            {
                switch (pad.ev.type)
                {
                    case JS_EVENT_INIT:
                    case JS_EVENT_INIT | JS_EVENT_AXIS:
                    case JS_EVENT_INIT | JS_EVENT_BUTTON:
                        break;
                    case JS_EVENT_AXIS:
                        pad.aPos[pad.ev.number] = pad.ev.value;
                        pad.changed = true;
                        break;
                    case JS_EVENT_BUTTON:
                        pad.bPos[pad.ev.number] = pad.ev.value;
                        pad.changed = true;
                        break;
                    default:
                        printf ("Other event ? %d\nnumber=%d\nvalue=%d\n",
                        pad.ev.type,pad.ev.number, pad.ev.value);
                        break;
                }
                result = read(pad.fd, &pad.ev, sizeof(pad.ev));
            } //else usleep(1);
               
            if (pad.changed)
            {
                printf ("----------------------------------------------\n");
                printf ("axis : %d\n", pad.axisCount);
                printf ("buttons : %d\n", pad.buttonCount);
                printf ("version : %d\n", pad.version);
                printf ("name : %s\n", pad.devName);
                printf ("----------------------------------------------\n");
                printf ("last ev time : %d\n", pad.ev.time);

                for (int i=0;i<pad.axisCount;i++) printf (" Axis %2d |",i);
                    printf ("\n");
                for (int i=0;i<pad.axisCount;i++) printf (" %7d |",pad.aPos[i]);
                    printf ("\n\n");
                for (int i=0;i<pad.buttonCount;i++) printf (" Btn.%2d |",i);
                    printf ("\n");
                for (int i=0;i<pad.buttonCount;i++) printf (" %2d |",pad.bPos[i]);
                    printf ("\n");
                pad.changed = false;
               
                std::stringstream outputstream;
               
                uint8_t ch1,ch2,ch3;
               
                ch1 = ((pad.aPos[0]-pad.aPos[1])/(256.0*256.0))*(ch1high-ch1low)+(ch1low+ch1high)/2- 2;
                ch2 = std::max(std::min(((-pad.aPos[1]-pad.aPos[0])/(256.0*256.0)),0.8),-1.0)*(ch2high-ch2low)+(ch2low+ch2high)/2- -4;
                std::cout << (int)ch1 << " " << (int)ch2 << std::endl;
                 
                ch3 = 150*pad.bPos[0]+20;
               
                outputstream << "#1&" << ch1 << "#2&" << ch2 << "#3&" << ch3;
                output = outputstream.str();
                std::cout << output.c_str() << std::endl;

                serial_port.flush();
                serial_port.write(output.c_str(),output.length());
            }
        }
        close(pad.fd);
    }
    else {
        printf ("failed to open /dev/input/js0\n");
    }
    return 0;
}




Youtube vid in a bit.

There is something awesome about driving a robot with a joystick

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Wed Jul 20, 2011 10:55 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  


_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Wed Jul 20, 2011 11:21 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Ok so thats nothing new we all saw Jakes custom interface many years ago.

However, I happened to notice that I had two Joystick interfaces in my /dev/input directory. I also noticed that one of them only seemed to move when I pushed on the joystick. After a short while I tried just pushing the laptop and I got a response.

Turns out it was the Macbooks IMU mapped to a Joystick interface.

I couldn't pick up the macbook while filming but its pretty cool to drive with it. Not practical or easy but cool none the less.


_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Wed Jul 20, 2011 11:42 pm 
 View user's profile Send private message Send e-mail MSN Messenger
Valen
Experienced Roboteer


Joined: 07 Jul 2004
Posts: 4436
Location: Sydney


 Reply with quote  

I'd suggest sticking with python for the PC side if you can,
I know i wound up making many changes on the fly ;->
_________________
Mechanical engineers build weapons, civil engineers build targets

Post Thu Jul 21, 2011 11:52 am 
 View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
Jaemus
Experienced Roboteer


Joined: 01 Apr 2009
Posts: 2674
Location: NSW


 Reply with quote  

haha thats pretty damn cool Smile
_________________
<Patrician|Away> what does your robot do, sam
<bovril> it collects data about the surrounding environment, then discards it and drives into walls

Post Thu Jul 21, 2011 8:33 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Been working on this again.

I now have a server which will let you control arrows "Virtual Robots" via a simple python script. Its not very fast so I am not sure what I should do about that or whether there is much which can be done.

Don has tested the script on his windoze PC up in gladstone and it can move the arrows on my home server but its pretty jerky. Not sure what the best method for improving this is. As its only going to get worse when I try and track the robot. How the hell do video games do it.

Anyway this sets up the server side of the remote robot driving. Now just need to track some robots.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Thu Nov 10, 2011 9:33 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Aaron just successfully drove one of my robots via an internet connection.

The I was connected to the robot via a PPM signal on my PC with a server running which was open to the internet. This was connected via wifi to my internet connection.

Aaron was using his computer with a tethered iphone to connect to the internet. Using this we were able to control the robot via the PC. First we made sure it was drivable just over the net then we tried driving it over skype.

Lag was a bit of a problem but next step is to do tracking. And send that back over the link so that video feed isn't the main form of feedback.

Another step forward plan is to have something in the arena which is running 24/7 sometime soon.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Sun Nov 20, 2011 2:24 am 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Don successfully drove a robot in the arena over a internet and skype link from Gladstone.

Lag over the video was a bit of a problem but I think this could be assisted by tracking the robot in the video. This however is not the easiest thing to achieve I have a few issues. Really what I am trying to do is track robots without additional features. It is more than possible but my image processing skills are probably not the best in the world so still lots of work to get going.

If anyone else wants to try driving over the net ping me on MSN.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Sun Nov 20, 2011 9:15 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  


_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Wed Nov 30, 2011 10:20 pm 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  



I failed hard at the video but making good progress.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Thu Dec 01, 2011 1:08 am 
 View user's profile Send private message Send e-mail MSN Messenger
marto
Experienced Roboteer


Joined: 08 Jul 2004
Posts: 5459
Location: Brisbane, QLD


 Reply with quote  

Every now and again a product comes along which makes this seem that little bit closer.

http://www.hobbyking.com/hobbyking/store/%5F%5F21430%5F%5FHobbyking%5FIOS%5FAndroid%5F4CH%5FWiFi%5FReceiver.html

This would mean that the custom interface should be able to be ditched and any computer with a Wifi connection used to communicate with the robots.

Makes things a bit easier. Although means that 2 Wifi connections are needed as they only have 4Ch. Not sure if this is a good or a bad thing atm. Will get the receiver then try and write a little Python App to control it and go from there.

Steve
_________________
Steven Martin
Twisted Constructions
http://www.botbitz.com

Post Fri Apr 27, 2012 3:21 pm 
 View user's profile Send private message Send e-mail MSN Messenger
  Display posts from previous:      

Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 5 of 9

Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9  Next

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Last Thread | Next Thread  >
Powered by phpBB: © 2001 phpBB Group
millenniumFalcon Template By Vereor.