Go Down

Topic: Android Bluetooth joystick (Read 331285 times) previous topic - next topic

tolisn63


You could presume that the pulse used for the add/delete waypoint would be the normal signal output by the movement of a R/C transmitters toggle switch ...thus Low and High... 1200 - 1800.





Well, the waypoint channel is controlled by one channel of the R/C receiver. This R/C receiver channel is controller by a two position switch on the R/C transmitter. What is the signal value for one position of the switch and what is the value for the other position, 1200 and 1800 ?.

woodygb

I'd need to actually read the values .... I can do this later if you wish ... but I'd say that it is a pretty safe bet that the signal is 1200 - 1800 ish .

The Ele , Aile , Rud & Throttle channels  ( joystick ) are certainly  1200 - 1500 - 1800 ish ..the ish  is to denote that there is always a slight variation from std.

Note that I have read the stick channel signals.... but never needed to read the Toggle switches

tolisn63


I'd need to actually read the values .... I can do this later if you wish ... but I'd say that it is a pretty safe bet that the signal is 1200 - 1800 ish .

The Ele , Aile , Rud & Throttle channels  ( joystick ) are certainly  1200 - 1500 - 1800 ish ..the ish  is to denote that there is always a slight variation from std.

Note that I have read the stick channel signals.... but never needed to read the Toggle switches


If you can do me this favour I'd really appreciate it. Please see the signal output for a 2 position toggle switch and a 3 position toggle switch if possible. Thanks for taking the time to reply.

woodygb

#333
Sep 05, 2014, 08:19 pm Last Edit: Sep 05, 2014, 08:49 pm by woodygb Reason: 1
Here you go .... a screen shot of the outputs of 3 channels.

Note that neither of my two RC Transmitters have a 3 way switch ...and I used what was this Arduino's  read rudder channel pin .... thus originally 3 positions ... to read the 2 way gear switch.

Ele  is the Throttle and Aile is the Steering





I might as well show the original screenshot before I deleted the center reading ...which is the "same" as one end of the scale.



The switch appears to have a 1100 - ( 1500) - 1900 signal range .... which is the "Norm" for  R/C .

tolisn63

Thanks a million for this, it saved me a lot or time.

kas

#335
Sep 06, 2014, 10:56 am Last Edit: Sep 06, 2014, 10:58 am by kas Reason: 1
@tolisn63
Buttons #1 (auto), #2 (manual) and #3 (learn) should be exclusive and configured as "radio buttons"
Assuming "auto" is the default mode, this is the way to go:
Code: [Select]
void getButtonState(int bStatus)  {
 switch (bStatus) {
// -----------------  BUTTON #1  -----------
   case 'A':
     buttonStatus |= B000001;    
     buttonStatus &= B111001;      // <<<<   radio button
     displayStatus = "<Manual>";
     myServo_Mode.writeMicroseconds(1800);
     break;
   case 'B':
     buttonStatus &= B111110;
     buttonStatus |= B000010;
     displayStatus = "<Auto>";
     myServo_Mode.writeMicroseconds(1200);
     break;

// -----------------  BUTTON #2  ----------
   case 'C':
     buttonStatus |= B000010;
     buttonStatus &= B111010;
     displayStatus = "<Auto>";
     myServo_Mode.writeMicroseconds(1200);
     break;
   case 'D':
     // no action
     break;

// -----------------  BUTTON #3  ----------
   case 'E':
     buttonStatus |= B000100;
     buttonStatus &= B111100;
     displayStatus = "<Learning>";
     myServo_Mode.writeMicroseconds(1500);
     break;
   case 'F':
     buttonStatus &= B111011;
     buttonStatus |= B000010;
     displayStatus = "<Auto>";
     myServo_Mode.writeMicroseconds(1200);
     break;

// -----------------  BUTTON #4  -----------------------
   case 'G':
   ...............


feel free to change buttons order


@woodygb
Thanks for your help  :)
Did you use BT Commander for a specific project ??
Let us have more info and photos

woodygb

#336
Sep 06, 2014, 11:16 am Last Edit: Sep 07, 2014, 12:38 am by woodygb Reason: 1
Hi Kas,

Yes ...I've used your Android App as the front end of a B.T. controlled wheelchair.


.


.

.



Thread here ...  http://www.wheelchairdriver.com/board/viewtopic.php?f=2&t=3790 ... the last few pages http://www.wheelchairdriver.com/board/viewtopic.php?f=2&t=3790&start=380are about the B.T.

Cheers Woody

woodygb

#337
Sep 06, 2014, 01:30 pm Last Edit: Sep 06, 2014, 01:39 pm by woodygb Reason: 1
Your seem to be using switches as the motor control...so ...you don't want "joystick" control ....just four compass points around the stick?

IF SO ... you could consider increasing the deadband out to around 90 ish  ...with the round joystick option selected.

This ... I THINK ...will give you four compass points on the extreme edge of the X,Y coordinates.

OR ...Consider a different App.

kas

Quote
Hi Kas,

Yes ...I've used your Android App as the front end of a B.T. controlled wheelchair.
Thread here ...  http://www.wheelchairdriver.com/board/viewtopic.php?f=2&t=3790 ... the last few pages http://www.wheelchairdriver.com/board/viewtopic.php?f=2&t=3790&start=380are about the B.T.

Cheers Woody



Interesting   :smiley-eek: :smiley-eek:
Feel free to propose any App modification

I have worked with a british artist on this project
The robot was based on wheelchair motors, and fitted with proximity sonic sensors to avoid bumping on furniture/people

I also suggest using a simple "dead man" failsafe in your code, to stop the chair if BT signal is lost


woodygb





Interesting   :smiley-eek: :smiley-eek:
Feel free to propose any App modification

I have worked with a british artist on this project
The robot was based on wheelchair motors, and fitted with proximity sonic sensors to avoid bumping on furniture/people

I also suggest using a simple "dead man" failsafe in your code, to stop the chair if BT signal is lost




I've put in a Neutral command for that eventuality.

Code: [Select]
void checkDeadMan()  {                                                  // stop engines if signal is lost
  static long previousMillis = 0;                             
  long currentMillis = millis();
  if(currentMillis - previousMillis > deadManInterval) {                // send data to smartphone
    previousMillis = currentMillis;
    if(deadManTimeout)  {
      BT_Steering = Neutral;
      BT_Throttle = Neutral; //Failsafe signal
      Rapidity=0;  // Reset to "FAST" speed ...Allows joystick to be used as normal when BT connection isn't present.
      int joyX = 200;
      int joyY = 200;
      digitalWrite(ledPin,LOW);

woodygb

#340
Sep 07, 2014, 10:17 am Last Edit: Sep 15, 2014, 09:08 am by woodygb Reason: 1
janzluc14

You could try this approach for your "mower".

Note that my coding skills aren't that great and it will probably need debugging....and I haven't bothered with the buttons.

Quote
( anything < > 70.71 will give a quadrant )
...that should be plus 70.71 and minus 70.71 depending on the quadrant.

Code: [Select]

   if (joyY  > 90 ) //.... forward  .. SELECT "CIRCLE" ... then 90 ( anything < > 70.71 will give a quadrant ) is used as a "deadband" to give four activation compass points
     forward();
   
   if (joyY  < -90 ) //.... backward
     backward();
   
   if (joyX  > 90 ) // .... turnright
     turnright ();
   
   if (joyX < -90 ) //..... turnleft
     turnleft();
     
   else
     motorwiper();    
   
 }
 
 void getButtonState(int bStatus)  {
   switch (bStatus) {
     // -----------------  BUTTON #1  -----------------------
   case 'A':
     buttonStatus |= B000001;        // ON
     Serial.println("\n** Button_1: ON **");
     // your code...    
     displayStatus = "LED <ON>";
     Serial.println(displayStatus);
     digitalWrite(ledPin, HIGH);
 
     break;
   case 'B':
     buttonStatus &= B111110;        // OFF
     Serial.println("\n** Button_1: OFF **");
     // your code...      
     displayStatus = "LED <OFF>";
     Serial.println(displayStatus);
     digitalWrite(ledPin, LOW);
     break;
 
     // -----------------  BUTTON #2  -----------------------
   case 'C':
     buttonStatus |= B000010;        // ON
     Serial.println("\n** Button_2: ON **");
     // your code...      
     displayStatus = "Button2 <ON>";
     Serial.println(displayStatus);
     break;
   case 'D':
     buttonStatus &= B111101;        // OFF
     Serial.println("\n** Button_2: OFF **");
     // your code...      
     displayStatus = "Button2 <OFF>";
     Serial.println(displayStatus);
     break;
 
     // -----------------  BUTTON #3  -----------------------
   case 'E':
     buttonStatus |= B000100;        // ON
     Serial.println("\n** Button_3: ON **");
     // your code...  
     motorwiper();    
     displayStatus = "Motor #1 enabled"; // Demo text message
     Serial.println(displayStatus);
     break;
   case 'F':
     buttonStatus &= B111011;      // OFF
     Serial.println("\n** Button_3: OFF **");
     // your code...    
     halt();  
     displayStatus = "Motor #1 stopped";
     Serial.println(displayStatus);
     break;
 
     // -----------------  BUTTON #4  -----------------------
   case 'G':
     buttonStatus |= B001000;       // ON
     Serial.println("\n** Button_4: ON **");
     // your code...      
     displayStatus = "Datafield update <FAST>";
     Serial.println(displayStatus);
     sendInterval = FAST;
     break;
   case 'H':
     buttonStatus &= B110111;    // OFF
     Serial.println("\n** Button_4: OFF **");
     // your code...      
     displayStatus = "Datafield update <SLOW>";
     Serial.println(displayStatus);
     sendInterval = SLOW;
     break;
 
     // -----------------  BUTTON #5  -----------------------
   case 'I':           // configured as momentary button
     //      buttonStatus |= B010000;        // ON
     Serial.println("\n** Button_5: ++ pushed ++ **");
     // your code...      
     displayStatus = "Button5: <pushed>";
     break;
     //   case 'J':
     //     buttonStatus &= B101111;        // OFF
     //     // your code...      
     //     break;
 
     // -----------------  BUTTON #6  -----------------------
   case 'K':
     buttonStatus |= B100000;        // ON
     Serial.println("\n** Button_6: ON **");
     // your code...      
     displayStatus = "Button6 <ON>"; // Demo text message
     break;
   case 'L':
     buttonStatus &= B011111;        // OFF
     Serial.println("\n** Button_6: OFF **");
     // your code...      
     displayStatus = "Button6 <OFF>";
     break;
   }
   // ---------------------------------------------------------------
 }
 
 void motorwiper()
 {
 
   dist = digitalRead(switchPin);    //read the switch
 
   if(dist != object)
   {                         //if distance is not equal to object
     forward();               //then move forward
   }
   if(dist == object)
   {               //if distance is equal to object
     findroute();
   }
 
 }
 
 void forward()
 {                            // use combination which works for you
   digitalWrite(motor_pin1,LOW);
   digitalWrite(motor_pin2,HIGH);
   digitalWrite(motor_pin3,HIGH);
   digitalWrite(motor_pin4,LOW);
 }
 
 void findroute()
 {
   halt();                                             // stop
   backward();                                       //go backwards
   turnleft();
 
   /*lookleft();                                      //go to subroutine lookleft
    lookright();                                   //go to subroutine lookright
   
    if ( leftdist < rightdist )
    {
    turnleft();
    }
    else
    {
    turnright ();
    }*/
 
 }
 
 /*void lookleft() {
 /*myservo.write(150);
  delay(700);                                //wait for the servo to get there
  leftdist = analogRead(sensorpin);
  myservo.write(90);
  delay(700);                                 //wait for the servo to get there
 
 
 
  }
  */
 
 
 /*void lookright () {
 
  myservo.write(30);
  delay(700);                           //wait for the servo to get there
  rightdist = analogRead(sensorpin);
  myservo.write(90);                                  
  delay(700);                        //wait for the servo to get there
 
 
  digitalRead(switchPin) = HIGH;
  }*/
 
 void backward() {
   digitalWrite(motor_pin1,HIGH);
   digitalWrite(motor_pin2,LOW);
   digitalWrite(motor_pin3,LOW);
   digitalWrite(motor_pin4,HIGH);
   delay(1000);
   halt();
 
 }
 
 void halt ()
 {
   digitalWrite(motor_pin1,LOW);
   digitalWrite(motor_pin2,LOW);
   digitalWrite(motor_pin3,LOW);
   digitalWrite(motor_pin4,LOW);
   delay(500);                          //wait after stopping
 
 }
 
 
 void turnleft ()
 {
   digitalWrite(motor_pin1,HIGH);       //use the combination which works for you
   digitalWrite(motor_pin2,LOW);      //right motor rotates forward and left motor backward
   digitalWrite(motor_pin3,HIGH);
   digitalWrite(motor_pin4,LOW);
   delay(1000);                     // wait for the robot to make the turn
   halt();
 
 }
 
 void turnright ()
 {
   digitalWrite(motor_pin1,LOW);       //use the combination which works for you
   digitalWrite(motor_pin2,HIGH);    //left motor rotates forward and right motor backward
   digitalWrite(motor_pin3,LOW);
   digitalWrite(motor_pin4,HIGH);
   delay(1000);                              // wait for the robot to make the turn
   halt();
 
 }

woodygb

#341
Sep 07, 2014, 12:29 pm Last Edit: Sep 15, 2014, 09:08 am by woodygb Reason: 1
janzluc14
Have a look at your digitalRead logic questions and answers received ... or not ...  http://arduino.cc/en/Tutorial/DigitalReadSerial  see if you can sort it out.

I'd also suggest that you only need to find the ON / HIGH state... so... IF it's HIGH find route ELSE  forward.  

Code: [Select]
void motorwiper()
 {
 
   dist = digitalRead(switchPin);    //read the switch
 
   if(dist != object)
   {                         //if distance is not equal to object
     forward();               //then move forward
   }
   if(dist == object)
   {               //if distance is equal to object
     findroute();
   }
 
 }

kas

Hi janzluc14,

As woodygb mentioned, your project belongs to the ON/OFF world, no joystick required
You may look for another App that will better fit your needs

Quote
sir their are times that when i put the joystick on forward and backward....the buttons will turn on automatically..is it because of the program???

Possible communication errors  :smiley-roll-blue: :smiley-roll-blue:
I understand your BT card is now set @57600bps
Please confirm that the basic demo sketch is working OK

Also make sure that
- Refresh Interval is set to 50ms
-Timeout count is set to 10 intervals

woodygb

#343
Sep 11, 2014, 08:17 pm Last Edit: Sep 15, 2014, 09:09 am by woodygb Reason: 1
janzluc14

Try this for your "Joystick"

Code: [Select]
void joystick()
{
 if (jy > 71 ){ //.... forward  .. SELECT "CIRCLE" in the App ... then use +-71 ( anything < -70.71  &  > 70.71 will give a quadrant ) is used as a "deadband" to give four activation compass points    
   forward();
   Serial.println (" FORWARD");
 }  
 if (jy< -71 ){ //.... backward
   backward();
   Serial.println (" BACKWARD");
 }
 if (jx  > 71 ){ // .... turnright
   turnright();
   Serial.println (" TURN RIGHT");
 }
 if (jx< -71 ){ //..... turnleft
   turnleft();
   Serial.println (" TURN LEFT");
 }
 if  ((jx > -71&&jx <71) && (jy > -71&&jy <71)) {  
   halt();
   Serial.println (" HALT");    
 }
}



There is an issue with the Delay (500) on halt  .... see if your button problems disappear if you make it Delay (10)

kas

#344
Sep 11, 2014, 09:36 pm Last Edit: Sep 11, 2014, 10:17 pm by kas Reason: 1
Quote
There is an issue with the Delay (500) on halt  .... see if your button problems disappear if you make it Delay (10)

You are right, delay() create issues with Serial communication
RX buffer is probably overflowing and generating unpredictable errors

Thanks for bringing up this point  ;)

Go Up