Pages: [1]   Go Down
Author Topic: Amarino  (Read 1343 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I've ordered a motor shield and I want to make this project at http://arduino.cc/forum/index.php/topic,90809.0.html but my motor shield used is the ladyada motor shield and the code is written for another motor shield. I've tried to fix this so it would work with my motor shield which is coming some time soon, it seems to compile without any errors but I just want someone that knows way more than me at this to help and see if this would work.
Code:
#include <AFMotor.h>
AF_DCMotor frontleft(1, MOTOR12_64KHZ);
AF_DCMotor frontright(2, MOTOR12_64KHZ);
AF_DCMotor backleft(3, MOTOR34_1KHZ);
AF_DCMotor backright(4, MOTOR34_1KHZ);

//Acceleration sensor from the smartphone is used to drive the robot forward backwords left and right

//inspired from http://www.arduino.cc/playground/Code/HTCDesire
//arduino + amarino + HTC Wildfire

#include <MeetAndroid.h>

#define IDLE 0
#define RINGING 1
#define OFFHOOK 2

MeetAndroid meetAndroid;

void setup() 
  {
    Serial.begin(115200);

    meetAndroid.registerFunction(phoneorient, 'A');
      int input=0;
      frontleft.setSpeed(255);
      frontright.setSpeed(255);
      backleft.setSpeed(255);
      backright.setSpeed(255);
  }

void loop()
  {
    meetAndroid.receive(); // you need to keep this in your loop() to receive events
  }

  void phoneorient(byte flag, byte numOfValues)
  {
    //Phone Orientation Controller
    int values[]={0,0,0};
    meetAndroid.getIntValues(values);

  int Steer=values[1];   //
  int Delta=values[2];   //
  int Heading=values[3];    //

  if (Steer >=5)

    {   //left

    frontright.run(BACKWARD);
    frontleft.run(FORWARD);
    backleft.run(FORWARD);
    backright.run(BACKWARD);
         
  }

  else if (Steer <=-5)
  { //right

    frontright.run(FORWARD);
    frontleft.run(BACKWARD);
    backleft.run(BACKWARD);
    backright.run(FORWARD);

  }

   else if (Delta >=5) { //forward
   
    frontright.run(FORWARD);
    frontleft.run(FORWARD);
    backleft.run(FORWARD);
    backright.run(FORWARD);

  }
     else if (Delta <=-5) { //back

    frontright.run(BACKWARD);
    frontleft.run(BACKWARD);
    backleft.run(BACKWARD);
    backright.run(BACKWARD);

  }

  else
 
  {
    frontright.run(RELEASE);
    frontleft.run(RELEASE);
    backleft.run(RELEASE);
    backright.run(RELEASE);

  }

    Serial.println(values[1]);  //Throttle  , Pitch
    Serial.println(values[2]);  //Steering, Roll
    Serial.println(values[3]);  // Heading, degree
}

It's a 4WD ground robot, I'm using a Galaxy Nexus and going to use a JY-MCU bluetooth module. Please reply to this thread, it would really help.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And I almost forgot, I want to add LED's to this project, which 4 pins would be available for my needs?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You would need someone else with an Android phone and a LadyAda motor shield to tear their project down and set yours up, to test that code. What do you suppose the odds are of that happening?

Just looking at the code, though, I can tell you that it won't work. It isn't just a shield issue, though.

A hint: Array indices start at 0.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup() 
  {
...
       int input=0;
...
  }

What does "input" do?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure, should I remove it?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it's not doing anything.



As PaulS hinted, this is wrong:

Code:
    int values[]={0,0,0};
    meetAndroid.getIntValues(values);

  int Steer=values[1];   //
  int Delta=values[2];   //
  int Heading=values[3];    //


Arrays start at 0, not 1. So (other things being equal) that should read:

Code:
    int values[]={0,0,0};
    meetAndroid.getIntValues(values);

  int Steer=values[0];   //
  int Delta=values[1];   //
  int Heading=values[2];    //

Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 50
Posts: 2210
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do one thing at a time - so first work on the motors drop all the rest!

Then sort the BT.

Then added them together.

But while you wait for the motor shield you could try making the built in LED on pin 13 blink.

Mark
Logged

Pages: [1]   Go Up
Jump to: