Useless Box Project (and random Arduino projects)

Cute kitten, I kinda like this one too :slight_smile:
https://www.youtube.com/watch?v=apVR5Htz0K4

Phil - sorry to hear about your fingers. Dang.

Anyhow - since you have a little one, I thought I would share my “Useless Box” from back in 2011 (pre x-carve - had to carve by hand back then!). This was for a birthday party. The coin on top neo magnets in it. When placed on top, the lid opens. The kids had to go on a scavenger hunt to find the coin and unlock the pirate chest. I also put a key switch on it for emergencies. I used a linear actuator (overkill… but it was what i had on hand). The chest was made from that super cheap pine glue up panel stuff at the Home Depot.

3 Likes

Those white strips are LEDSs. The black thing strapped to the actuator is an amplified speaker. It played pirate music when it opened.

1 Like

Add this to the list of useless stuff I need to make this summer lol

1 Like

It is the Arduino code to tell a servo to go from 80 degrees to 155 degrees…it is not really less than in this case.

1 Like

It is more a direction indicator:

for example:

Blockquote
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}

you don’t really need the “=” either…it can be just:

// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++)
{
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 0; angle–)
{
servo.write(angle);
delay(15);
}

1 Like

it is just a variable…as long as it is declared above in code somewhere…yours is pos so use that.

1 Like

It might be helpful to put it another way using the word: WHILE.

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees MEANS:

  1. Set “pos” to zero. “pos” was defined elswhere and set to a different value possibly. If it was not defined else where, then this would have to read: for (int pos = 0… because you have to declare the variable, in this case as an integer.
  2. WHILE pos is less than or equal to 180, increment pos by 1 and go through the loop.
  3. Each time through the loop make sure that adding 1 does not cause “pos” to exceed 180. It can BE 180 but cannot exceed 180 because you used less than or equal to.
2 Likes

that is just 1 at a time…either plus one ++, or minus one –

so move 1 wait 15ms…rinse and repeat :slight_smile:

1 Like

Sorry Phil, but since Erik and Angus are here… I am dealing with a similar issue in that I want to drive two brushless motor ESCs with a dual axis pot (joystick) to provide steering. JUST IN CASE either of you have tackled that, I would love to see the alogrithm. I thought it might be something you guys may have messsed with in the past. I am making a mini TESLA using brushless hoverboard motors (cheap and amazingly powerful) and the new Brushless RAGE from Equals Zero designs (http://e0designs.com/products/brushless-rage/).

2 Likes

That sounds pretty cool, but that would be new for me…sorry.

What is controlling this…“brains”? Arduino?

yep

Everything is working. I was just looking for advice on MIXING the forward/reverse with left and right for smooth steering.

Here is a discussion on this topic…it might be useful: Algorithm for mixing 2 axis analog input to control a differential motor drive - Electrical Engineering Stack Exchange

EDIT: sorry about the thread @PhilJohnson…can a moderator move this discussion?

1 Like

Wow - this is great - I have been searching the nets and have not found this particular article. Step one is to figure this out. Then, each ESC has its own computer that needs to be programmed with braking, torque, and like six other factors I do not understand for maximum smoothness. Right now, if you sit on this thing and push the stick forward, you WILL flip off the back. When you stop, you flip off the front. Steering is NOT smooth. So, once an ideal mix is determined, I will start working on torque curves. These motors are so cheap because of the hoverboard craze, I would think this could become a popular project.

1 Like

Can you share what you have? I have a bit of experience using ESCs with Arduino.
Are you using one for drive and one for turning or are you driving independent for each side?

Proportional control of each side. So, full forward would be sending full forward signals to two ESCs. These are brushless motors so they each must have their own ESC. Here is my beginning code. So far, I just have the “FORWARD” case working with good mixing, there is also a REVERSE case and a Neutral case - so I can eventually have zero degree turning in the neutral case with more sophisticated mxing in forwad and reverse.

Sorry this is littered with notes:

/*
Brushless Rage Mixed Control

*/

#include <Servo.h>

Servo rage1; // create servo object to control a servo
Servo rage2; // create servo object to control a servo
float TurnFactor = 0;
int potpin = 0; // analog pin used to connect the potentiometer
int potpin2 = 1; // analog pin used to connect the potentiometer
int Speed = 90; // variable to read the value from the analog pin
float Direction = 90; // variable to read the value from the analog pin
int leftOut;
int rightOut;
int FWD_Trigger = 480; // Less than 480 is forward motion
int RVS_Trigger = 535; // Greater than 526 is Reverse

void setup() {
rage1.attach(9); // attaches the servo on pin 9 to the servo object
rage2.attach(10); // attaches the servo on pin 9 to the servo object
Serial.begin(19200);

}

void loop() {
Speed = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
Direction = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023)

     // scale it to use it with the servo (value between 0 and 180)

// RAW DATA FROM RAGES: FWD MAX SPEED = 275 RVS MAX SPEED = 728
// MIN FWD = 480 RVS MIN SPEED = 526
// FULL Forward = 0
// Max Reverse = 900 (Or Shutdown)
// So - 0 to 900 = Full FWD to Full RVS
// FWD = <480
// RVS = > 526
//
// F O R W A R D | Neutral | R E V E R S E
// 0 480| |526 900| BAD SHUTDOWN >900
//
// NEXT: Translate figures above into 0-180 values

// ************* FORWARD MOTION ***************

if (Speed <= FWD_Trigger){
  Speed = map(Speed, 0, 1023, 179, 0);
  Direction = map(Direction, 0, 1023, 0, 179);
  
  Direction = Direction - 90;

    if (Direction <=-10){
      //  ***********   RIGHT TURN *****************************
      TurnFactor = (abs(Direction))/100;

      rightOut = Speed - (Speed * TurnFactor);             //Add Velocity to right wheel
      leftOut = Speed + (Speed * TurnFactor);    // Subtract Velocity from left wheel
    }
    else if (Direction >=10){
    //  ***********   LEFT TURN *****************************
       TurnFactor = ((abs(Direction))/100);

      Speed = map(Speed, 0, 1023, 179, 0);
      float TurnFactor = (Direction)/100;
      leftOut = Speed - (Speed * TurnFactor);             //Add Velocity to left wheel
      rightOut = Speed + (Speed * TurnFactor);    // Subtract Velocity from right wheel
    }
  else {
    leftOut = Speed;
    rightOut = Speed;}
  

 leftOut = constrain(leftOut, 99, 179);
rightOut = constrain(rightOut, 99, 179);
rage1.write(leftOut);                  // sets the servo position according to the scaled value//
rage2.write(rightOut);
Serial.print("FORWARD "); Serial.print("Left: ");Serial.print(leftOut);Serial.print("Right: ");Serial.print(rightOut); Serial.print("Trig: "); Serial.println(analogRead(potpin));

}

// ************* REVERSE MOTION ***************
else if (Speed >= RVS_Trigger){

  Speed = map(Speed, 0, 1023, 179, 0);
  Direction = map(Direction, 0, 1023, 0, 179);
  Direction = Direction - 90;
    if (Direction <=0){
      //Turn Right
    }
    else {
    //Turn Left
    }
  rage1.write(leftOut);                  // sets the servo position according to the scaled value//
  rage2.write(rightOut);
   Serial.print("REVERSE "); Serial.print("Left: ");Serial.print(leftOut);Serial.print("Right: ");Serial.print(rightOut); Serial.print("Trig: "); Serial.println(analogRead(potpin));
}

// ************* NEUTRAL MOTION ***************
else {
Speed = map(Speed, 0, 1023, 179, 0);
Direction = map(Direction, 0, 1023, 0, 179);
Direction = Direction - 90;
if (Direction <=0){
//Zero Degree Turn Right
}
else {
//Zero Degree Turn Left
}
leftOut = 90;
rightOut = 90;
rage1.write(leftOut); // sets the servo position according to the scaled value//
rage2.write(rightOut);
Serial.print("NEUTRAL "); Serial.print("Left: ");Serial.print(leftOut);Serial.print("Right: ");Serial.print(rightOut); Serial.print("Trig: "); Serial.println(analogRead(potpin));

}

}

What’s it doing now that you want to improve?