Saturday, December 26, 2015

Attiny Canbot

Introduction


There were a few projects in the last year that just didn't work. Mostly because they were too ambitious and I did not have enough time and pacience to finish them. So I finally wanted to build a robot that just works without any gimmicks.

Electronics

The main part of the robot is an Atttiny85 again.
The servos are two HXT900 from Hobbyking:
 http://www.hobbyking.com/hobbyking/store/__662__HXT900_9g_1_6kg_12sec_Micro_Servo.html
I removed the potentiometers and the end stops, so that they are continuously rotating.
I am using a 3,7V 600mAh LiPo to power both the Attiny and the servos. A small power switch disconnects the battery after use.
An HC-SR04 ultrasonic sensor enables autonomous driving to a certain degree.
To control the robot a 38kHz infrared receiver is needed as well.




Hardware

For the body of the robot I wanted to make use of my 3D printer. There are two half shells that hold the servos, the ultrasonic sensor and all remaining electronic components. These halves are connected by four screws. The holes are designed to fit the mounting screws that came with the servos.  Both wheels are screwed into the servo shafts. The heavier parts like the battery need to be in the lower half to help the robot remain balanced.



The stl-files are available on Thingiverse:


Depending on your printer and servos you will have to sand the shells down a bit. The remaining electronical parts are then just hot-glued in.

Programming

This part was pretty simple as well, because I could reuse most of the code from my biped robot (http://coretechrobotics.blogspot.de/2013/12/an-attiny85-ir-biped-robot.html).
The Attiny will listen for infrared signals and moves the servos depending on what it receives.
I also built in an autonomous mode than can be activated by pressing a certain key on the remote. It simply drives forward until the ultrasonic sensor detects an obstacle, then it turns and drives on.
You can download the code from the Thingiverse page or directly from Dropbox:

https://www.dropbox.com/s/g5myobjc0wyziqw/Canbottiny_source.zip?dl=1

Keep in mind that this particular code may not work for you if you don't have the same Sony remote as me. You will have to change the codes at least, maybe it won't work at all.

Conclusion

As this robot was just supposed to be a qick weekend project, I am very happy with the overall outcome. A lot of people on Thingiverse seemed to like it as well and a few even built replicas. The only problem left is the balancing. If you want the robot to stay level while rolling, you will have to put some additional weight in the lower half. 

15 comments:

  1. Hai,

    Beautiful project thank you for sharing it with us
    May I ask where the IR receiver for the remote control is

    Kind regards

    ReplyDelete
    Replies
    1. Thanks!
      The IR receiver does not have a special place in the robot.
      At the moment it is attached to the board by its wires and stuck somewhere behind the battery.
      Apparently the white PLA is letting through enough light for the receiver to work.
      If you want longer range you could drill a hole in the top part as someone did here:
      http://www.thingiverse.com/make:184442

      Delete
    2. Hai Max,

      Thank you for the quick answers and the information
      I want to print the "Top.stl" 2x, and the HC-SR04 to get away so I only have the servos and the IR receiver
      My intention is in fact to make my lazy cat more active, so I only need the remote
      Now my shy question, could you write a program to control the canbot via IR remote control without the HC-SR04 sensor
      I am a creator and a bad programmer sorry

      Kind regards

      Delete
    3. The ultrasonic sensor is not that important.
      If you don't connect it to the Attiny everything is still going to work with the code I provided (except for the autonomous mode).

      Delete
    4. Hai Max

      Thanks for the info
      I will try

      Kind regards

      Delete
  2. Hi Max,

    This is great, and I really wanted to make it so I've sourced all the parts etc etc however I have a slight issue and I wonder if you may be able to assist. Can you tell me specifically what IR sensor you're using? I've tried a few different one all 38Khz with Numerous different remotes, however the IR Code just doesn't work as expected.

    No matter what key I press, it start as a 0 or a 3 or a 7 (it's apparently random-ish) and a prolonged press always results in 15 (Using serial.debug). I'm using the code on an Arduino Nano initially to test but even on the ATTiny85 I get the same results (Using a USBTiny bridge to capture serial output in terminal).

    ReplyDelete
    Replies
    1. The sensor I am using is a OS-838g:
      http://www.produktinfo.conrad.com/datenblaetter/175000-199999/184294-da-01-en-IR_RECEIVER_2_7_5_5V_OS_838G.pdf
      It seems to only be available in Germany, but as long as it's 38kHz any sensor should work.
      I got the infrared code from this forum thread:
      http://forum.arduino.cc/index.php/topic,17965.0.html
      The problem is that all brands of remotes have almost entirely different protocols and this particular code works best for Sony remotes.
      You could either try adapting the code from the Arduino forum to your remote or get a universal remote and configure it to act as a Sony remote.

      Delete
    2. Hi Max,

      Thanks for the reply, having done some further IR Test, ALL the remotes I have (and I have quite a few from cheap LEDs, old camera, a projector, a car remote) ... ALL would you believe it use NEC codes. I'm going to order a cheap Sony remote from eBay and see if that works any better for me :)

      Many thanks for your response

      Delete
  3. can you please modify the code to make it work without ir reciver?

    ReplyDelete
    Replies
    1. I will look into this but I don't have time at the moment.
      Maybe it will be faster if you try to figure it out by yourself.
      Basically you just have to place this into the loop:

      if(getDistance() < 10){ // check if you are in front of an obstacle
      moveMotors(94, 20); // drive backward in a curve
      delay(400); // give the robot time to balance out
      }
      else{
      moveMotors(120, 120); //drive straight forward
      }

      Delete
  4. There's a mistake in the schematic I think the + of the ATtiny85 is pin 8 and - of ATtiny85 is pin 4

    ReplyDelete
    Replies
    1. Thank you! I didn't notice that. Not only the power pins are wrong, the whole chip seems to be upside down.
      I hope you didn't fry your Attiny because of that :|

      Delete
    2. That's the game of the play , this learning money
      It still work to do , it does not work as it should,

      http://www.thingiverse.com/make:220599

      Kind regards

      Delete