Wifi controlled robot

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
chien_fu
 
Posts: 12
Joined: Tue Dec 10, 2013 9:53 am

Wifi controlled robot

Post by chien_fu »

I'm trying to use the cc3000 to control my robot remotely. And from what I can tell about this tutorial (https://learn.adafruit.com/wifi-controlled-mobile-robot) it will only work if you are on the same wifi network. Is that correct? I would like to control my robot from another network. Does anyone know if there is a way to do that?

Thanks!

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Wifi controlled robot

Post by Franklin97355 »

Where are you in this project? Have you gotten the robot to work locally (on the same network)? Will you know what the network info is for the other network and if not how do you plan to find your bot?

User avatar
jsmcms
 
Posts: 6
Joined: Wed Mar 13, 2013 5:39 pm

Re: Wifi controlled robot

Post by jsmcms »

Hi Guys, Has anyone used a Adafruit V2 motor shield in this project? I am a programming novice but I can usually "adjust" code to make things work. Alas, I have no success using this shield. I've got the server work, I just can't get the motors to work. Any help would be appreciated. Scott

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Wifi controlled robot

Post by Franklin97355 »

Any help would be appreciated. Scott
Start by posting your code and be sure to use the code button (</>) above the post window.
2014-06-30_17h43_42.png
2014-06-30_17h43_42.png (2.97 KiB) Viewed 411 times

User avatar
jsmcms
 
Posts: 6
Joined: Wed Mar 13, 2013 5:39 pm

Re: Wifi controlled robot

Post by jsmcms »

Hi Franklin, I am using the software that was posted on your web site for the project. No changes, so far. Scott

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Wifi controlled robot

Post by Franklin97355 »

OK, I guess it's time for some pictures. Post clear photos of all your boards and one of the motors you are using. When you run the code what output do you get?

User avatar
jsmcms
 
Posts: 6
Joined: Wed Mar 13, 2013 5:39 pm

Re: Wifi controlled robot

Post by jsmcms »

Photo 1r.JPG
Photo 1r.JPG (453.88 KiB) Viewed 389 times
Photo 1 is the V2 board setup. I am feeding the board with power and using the jumper to back feed the Uno and CC3000 shield. You'll see that all four DC motor connections are used. I realize that I may have to change this but I'm just trying to get it working. You'll also see that I rigged a simple LED for trouble shooting.
Photo 5r.JPG
Photo 5r.JPG (434.23 KiB) Viewed 389 times
Photo 5 is a screen snapshot after sending the first command to the robot. As you will see, the CC3000 connects and receives the first transmission but hangs up from there.
Photo 4r.JPG
Photo 4r.JPG (370.55 KiB) Viewed 389 times
Photo 4 is the V2 board after the transmission indicating that the forward command was received. However, the motors do not turn.

User avatar
jsmcms
 
Posts: 6
Joined: Wed Mar 13, 2013 5:39 pm

Re: Wifi controlled robot

Post by jsmcms »

Hi Guys,

Well, I've made some progress but I stuck. I'm hoping some of you smart programming guys can see what I'm doing wrong and help me fix it. Here's what I'm trying to do:

I'm trying to use the existing code to operate a four (4) motor robot using the V2 board. I've got one motor connected to each DC motor output. I've successfully tested that all four motors work using a modified Buildtest but when I try to incorporate that method into the Wifi Controlled Robot code, I keep having problems.

I think my trouble is how the send_motor_command works. I confess I don't fully understand how it work and I'm not sure how I can make it work for four motors without changing the server programs. I'm hoping I don't have to change the server stuff and I'm just missing something.

Here's the beginning of the sketch:

Code: Select all

/* 
*  Simple robot control with Arduino & the CC3000 WiFi chip
*/

// Include required libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include <stdlib.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

String result;
int motorCommand[4];

// Define CC3000 chip pins

#define LEDStatPin 4
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
#define ADAFRUIT_CC3000_SCK 13
#define ADAFRUIT_CC3000_MISO 12
#define ADAFRUIT_CC3000_MOSI 11


// Motor Control
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
int speed_motor1;  
int speed_motor2;
int direction_motor1;
int direction_motor2;
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMS.getMotor(3);
Adafruit_DCMotor *myMotor4 = AFMS.getMotor(4);

Here's the send_motor_command stuff that I've botched pretty well:

Code: Select all

 // Format result and extract the variables
    format_result(motorCommand,result);
 
    // Print received values
    Serial.println("Motor 1 speed: " + String(motorCommand[0]) + " and direction: " + String(motorCommand[2]));
    Serial.println("Motor 2 speed: " + String(motorCommand[1]) + " and direction: " + String(motorCommand[3]));

    // Send motor commands
    send_motor_command(speed_motor1,direction_motor1,motorCommand[0],motorCommand[2]);
    send_motor_command(speed_motor2,direction_motor2,motorCommand[1],motorCommand[3]); 

    // Reset result variable
    result = "";  
       
  }
}  
    
void send_motor_command(int speed_pin, int direction_pin, int pwm, boolean reverse){
    AFMS.begin (1600);
//    if (speed_pin = 1){

    myMotor2->setSpeed(pwm);
    myMotor3->setSpeed(pwm);
    myMotor2->run(RELEASE);
    myMotor3->run(RELEASE);
//   }
//   else
//   {
//    myMotor1->setSpeed(pwm); 
//    myMotor4->setSpeed(pwm);
//    myMotor1->run(RELEASE);
//    myMotor4->run(RELEASE); // Set PWM control, 0 for stop, and 255 for maximum speed
  if(reverse)
  { 
//    myMotor1->run(BACKWARD);
    myMotor2->run(BACKWARD);
    myMotor3->run(BACKWARD);
//    myMotor4->run(BACKWARD);    
  }
  else
  {
//    myMotor1->run(FORWARD);
    myMotor2->run(FORWARD);
    myMotor3->run(FORWARD);
//    myMotor4->run(FORWARD);    
  }
}
If it would help, I can make a video to show how everything is not working right.

Thanks in advance, Scott

User avatar
jsmcms
 
Posts: 6
Joined: Wed Mar 13, 2013 5:39 pm

Re: Wifi controlled robot

Post by jsmcms »

Second try. Can anyone help?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Wifi controlled robot

Post by Franklin97355 »

Perhaps if you asked a single specific question some one would have an answer.

User avatar
jsmcms
 
Posts: 6
Joined: Wed Mar 13, 2013 5:39 pm

Re: Wifi controlled robot

Post by jsmcms »

My apologies. I thought I had done that. I'll try it this way.

Can someone give me some help on rewriting the code to accommodate the Adafruit V2 motor sheild? I think if I could understand how the relationship between the "send_motor_command(..." and the how it would be adopted to the V2 terminology, I'd be able to sort it out.

Thanks, Scott

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Wifi controlled robot

Post by adafruit_support_bill »

The SendMotorCommand does not map directly into V2 commands. It can be done, but it would be a little awkward. Better to take the direct approach and replace SendMotorCommand with the corresponding motor commands.

Code: Select all

    myMotor2->setSpeed(motorCommand[0]);
    myMotor3->setSpeed(motorCommand[1]);
    if (motorCommand[2])
       myMotor2->run(BACKWARD);
    else
       myMotor2->run(FORWARD);
    if (motorCommand[3])
       myMotor3->run(BACKWARD);
    else
       myMotor3->run(FORWARD);

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”