Go Down

Topic: Simple WiiRemote Bluetooth Robot (Read 1 time) previous topic - next topic

rameses32

Here is a video of it so far. http://www.youtube.com/watch?v=LZ-nfHzsGeM
It's an extremely simple platform, just 2 modified nine gram servos I got from Ebay for $2.50 each and a $2 Bluetooth Dongle.
Charley


Here is the Sketch
Quote


#include <WiiRemote.h>
#include <Servo.h>

#define STEERING_ANGLE_MAX    160
#define STEERING_ANGLE_MIN    20
#define STEERING_ANGLE_CENTER 90
#define STEERING_ANGLE_STEP   5
Servo Left_servo;  // create servo object to control a servo
Servo Right_servo;
int deg1;
int a;
WiiRemote wiiremote;

void setup()
{
  
  wiiremote.init();
  Left_servo.attach(6);  // attaches the servo on pin 3 & 6 to the servo objects
  Right_servo.attach(3);

  }
void loop(){
 Left_servo.attach(6);  // attaches the servo on pin 3 & 6 to the servo objects
  Right_servo.attach(3);
  wiiremote.task(&myapp);
  }


void myapp(void) {
  
    int steering_angle = getSteeringAngle();
  }


int getSteeringAngle(void) {
  double rad; // y accel setup
  double deg; // y accel setup
  double rad2; // X accel setup
  double deg2; // X accel setup

  rad = acos((double) wiiremote.Report.Accel.Y);
  deg = rad * 180.0 / PI;
  
  rad2 = acos((double) wiiremote.Report.Accel.X);

  deg2 = rad2 * 180.0 / PI;

  /* clipping */
  if (deg2 > STEERING_ANGLE_MAX) { deg2 = STEERING_ANGLE_MAX; }
  else if (deg2 < STEERING_ANGLE_MIN) { deg2 = STEERING_ANGLE_MIN; }
  
  if (deg > STEERING_ANGLE_MAX) { deg = STEERING_ANGLE_MAX; }
  else if (deg < STEERING_ANGLE_MIN) { deg = STEERING_ANGLE_MIN; }
  
if (deg2 >= 85 && deg2 <= 95) { Left_servo.detach(); //eliminates drift at servo center position
Right_servo.detach(); }

if (deg2 > 90) { a = deg2 - 90; //Inverts output to reverse right servo
deg1 = 90 - a;
}
else if (deg2 < 90) {a = 90 - deg2;
deg1 = 90 + a;
}
   
if (deg >= 80 && deg <= 100) {
   Left_servo.write(deg2);
   Right_servo.write(deg1);
}
else if (deg < 80) {
  Right_servo.write(deg1);
  Left_servo.write(90);
}
else if (deg > 100) {
  Left_servo.write(deg2);
  Right_servo.write(90);
}
}


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy