Hello then show you a robot which is controlled by visual basic
through a wifi network with WINSOC.
The project is a Visual Basic 6.0 application I can connect the
Arduino wifi module to a home wireless network, I can control with visual
my robot to see what else I can catch the robot sensors, in
this case an accelerometer but you can view data
sharp sensors.
The interface is very simple to have an EditText IP address, a
for the port and the switching on and off button.
Tex in the edit that says "Put Mouse Pointer Here" puts the pointer
mouse and arrow keys can now control your robot if
want self, there is a corresponding button for this and the other for
return it to the control mode.
Hope you like it
Annex the arduino code and the project in VB6.
Thanks.
jaimico
for codes of the project:
Codes VB6
http://www.2shared.com/file/5HoGGZ23/Cliente_VB.html
Arduino:
#include <WiShield.h>
#include <Servo.h>
#define VOLTS_PER_UNIT .0049F // (.0049 for 10 bit A-D)
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
byte local_ip[] = {your ip}; // IP address of WiShield
byte gateway_ip[] = {your gateway_ip}; // router or gateway IP address
byte subnet_mask[] = {your subnet_mask }; // subnet mask for the local network
prog_char ssid[] PROGMEM = {"YOUR_SSID"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"big_secret"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
Server server(80);
Client client_a;
int Dato = 0;
byte A =0;
word X1 = 0;
word Y1 = 0;
word Z1 = 0;
word Dis = 0;
float volts = 0.0;
float inches = 0.0;
float cm = 0.0;
float cm_1 = 0.0;
float cm_2 = 0.0;
Servo myservo_0;
Servo myservo_1;
Servo myservo_2;
void setup(){
Serial.begin(9600);
WiFi.begin(local_ip, gateway_ip, subnet_mask);
server.begin();
myservo_0.attach(5);
myservo_1.attach(6);
myservo_2.attach(7);
Cero();
}
void loop(){
Wifi_Ardu();
Serial.println("loop");
}
void Wifi_Ardu(){
if(!client_a.connected()) {
server.available(&client_a);
client_a.println("Conecto");
}else{
while(client_a.available()){
// Captura datos del acelerometro
X1 = analogRead(4);
Y1 = analogRead(3);
Z1 = analogRead(5);
client_a.print("#");
client_a.print(X1);
client_a.print("$");
client_a.print(Y1);
client_a.print("%");
client_a.println(Z1);
//--------------------------------------------------------
//--------------------------------------------------------
char c = (char)client_a.read();
A = c;
Serial.println(A);
if(A==65){
Adelante();
}else if(A == 66){
Atras();
}else if(A == 67){
Izquierda();
}else if(A == 68){
Derecha();
}else if(A == 69){
Cero();
}else if(A==70){
Autonomo();
}
}
}
}
void Autonomo(){
while(1){
while(client_a.available()){
Cal_Dis_0();
Cal_Dis_1();
Cal_Dis_2();
Evadir_OBJ();
char c = (char)client_a.read();
A = c;
Serial.println(A);
if(A==71){
Serial.println("ntro");
return;
}else{}
}
}
}
void Cal_Dis_0(){
Dis = analogRead(0);
volts = (float)Dis * VOLTS_PER_UNIT; // ("proxSens" is from analog read)
inches = 23.897 * pow(volts,-1.1907); //calc inches using "power" trend line from Excel
cm = 60.495 * pow(volts,-1.1904); // same in cm
if (volts < .2) inches = -1.0;
//Serial.println(cm);
}
void Cal_Dis_1(){
Dis = analogRead(1);
volts = (float)Dis * VOLTS_PER_UNIT; // ("proxSens" is from analog read)
inches = 23.897 * pow(volts,-1.1907); //calc inches using "power" trend line from Excel
cm_1 = 60.495 * pow(volts,-1.1904); // same in cm
if (volts < .2) inches = -1.0;
//Serial.println(cm_1);
}
void Cal_Dis_2(){
Dis = analogRead(2);
volts = (float)Dis * VOLTS_PER_UNIT; // ("proxSens" is from analog read)
inches = 23.897 * pow(volts,-1.1907); //calc inches using "power" trend line from Excel
cm_2 = 60.495 * pow(volts,-1.1904); // same in cm
if (volts < .2) inches = -1.0;
//Serial.println(cm_2);
}
void Evadir_OBJ(){
if(cm < 20){
Atras();
Busca();
}
if(cm_1 < 20){
Izquierda();
delay(100);
}
if(cm_2 < 20){
Derecha();
delay(100);
}
if(cm > 20 && cm_1 > 20 && cm_2 > 20){
Adelante();
}else{}
}
void Busca(){
while(1){
Izquierda();
if(cm_2 < 20){
Derecha();
delay(100);
break;
}else{
break;
}
}
while(1){
Derecha();
if(cm_1 < 20){
Izquierda();
delay(100);
break;
}else{
break;
}
}
}
void Atras(){
myservo_0.write(140);
delay(15);
myservo_1.write(160);
delay(15);
}
void Adelante(){
myservo_0.write(160);
delay(15);
myservo_1.write(140);
delay(15);
}
void Izquierda(){
myservo_0.write(140);
delay(15);
myservo_1.write(140);
delay(15);
}
void Derecha(){
myservo_0.write(160);
delay(15);
myservo_1.write(160);
delay(15);
}
void Cero(){
myservo_0.write(150);
delay(15);
myservo_1.write(150);
delay(15);
myservo_2.write(150);
delay(15);
}
No hay comentarios:
Publicar un comentario