My Projects

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

arduino:Controller_for_Cybot [2018/09/26 22:39]
tony
arduino:Controller_for_Cybot [2021/07/30 15:55] (current)
tony
Line 4: Line 4:
 \\ \\
  
-I have received a discarded Cybot robot which is mostly complete and decided to replace its control chips with an Arduino, which will require writing software to control the motors and receive inputs from the ultrasonic and LDR sensors.+I have received a discarded Cybot robot which is mostly complete and decided to replace its control chips with an Arduino, which will require writing software to control the motors and receive inputs from the ultrasonic and LDR sensors.  There are quite a few projects on the internet that reuse the Cybot hardware but replace or modify the sensors and interface boards -  the objective with this project is to make a substitute for the processor board, that can plug into any other unmodified Cybot.
  
 <​HTML>​ <​HTML>​
Line 16: Line 16:
    
 ===== Overview ===== ===== Overview =====
-Surprisingly the Cybot was in basic working order, although the front caster wheel was missing. Fortunately the batteries ​hadn'​t ​leaked, and after replacing them it fired up ok. But as an autonomous robot it doesn'​t ​perform brilliantly,​ and could do with a bit more sophistication.+Surprisingly the Cybot was in basic working order, although the front caster wheel was missing. Fortunately the batteries ​had not leaked, and after replacing them it fired up ok. But as an autonomous robot it does not perform brilliantly,​ and could do with a bit more sophistication.
  
 ===== Hardware description ===== ===== Hardware description =====
-The Cybot was originally built in stages from kitset parts supplied with a magazine. It is built on a three wheeled platform, with two independent driving wheels and one caster wheel to balance the front. There is a 6 volt battery holder for the wheels and a separate 9V battery to drive the electronics. Interface and controller boards are modular and plug together as more features are added. There were a number of stages, developing eventually to a remote controlled beast. But the one I have was just at the end of the first stage, it has two powered wheels with an H-bridge control circuit made of discrete components, two Light Dependant ​Resistors (LDRs) for detecting light sources, a line following module, and two pairs of ultrasonic transmitter/​receivers for detecting its environment.+The Cybot was originally built in stages from kitset parts supplied with a magazine. It is built on a three-wheeled platform, with two independent driving wheels and one caster wheel to balance the front. There is a 6-volt battery holder for the wheels and a separate 9V battery to drive the electronics. Interface and controller boards are modular and plug together as more features are added. There were a number of stages, developing eventually to a remote-controlled beast. But the one I have was just at the end of the first stage, it has two powered wheels with an H-bridge control circuit made of discrete components, two Light Dependent ​Resistors (LDRs) for detecting light sources, a line following module, and two pairs of ultrasonic transmitter/​receivers for detecting its environment.
  
-Using the ultrasonic sensors appears to be the most difficult part. They have a fairly minimal interface, but from 3rd party documentation should produce 40kHz pulses when something reflects the signal, perhaps an interrupt driven routine will be useful. There are a few other projects on the Internet that have made these types of modifications,​ but all seem to have skipped the ultrasonic sensors, some even add other more sophisticated ultrasonic range finding hardware instead.+Using the ultrasonic sensors appears to be the most difficult part. They have a fairly minimal interface, but from 3rd party documentation should produce 40kHz pulses when something reflects the signal, perhaps an interrupt-driven routine will be useful. There are a few other projects on the Internet that have made these types of modifications,​ but all seem to have skipped the ultrasonic sensors, some even add other more sophisticated ultrasonic range finding hardware instead.
  
-There appears to be a requirement for 14 I/O pins from the controller.+There appears to be a requirement for 15 I/O pins from the controller.
  
-The Light I/O board: +The Light I/O board:\\ 
-<​HTML>​ + 
-<​table><​tbody>​ +^Direction^Label^Description| 
-  <​tr><​td width="​10%"><​b>​Direction</​b></​td><​td width="​10%"><​b>​Label</​b></​td><​td><​b>​Description</​b></​td></​tr>​ +|I|L_F|line follower input| 
-  <​tr><​td>​I</​td><​td>​L_F</​td><​td>​line follower input</​td></​tr>​ +|O|buzzer 1|buzzer driver output| 
-  <​tr><​td>​O</​td><​td>​buzzer 1</​td><​td>​buzzer driver output</​td></​tr>​ +|O|buzzer 2| - drive one high and one low at the same time, gives 10V across transducer| 
-  <​tr><​td>​O</​td><​td>​buzzer 2</​td><​td>&​nbsp;&​nbsp;​not sure why there are two pins, maybe like the ultrasonics it needs 10V p-p</​td></​tr>​ +|I/O|LDR left|light dependent resistor input/​discharge| 
-  <​tr><​td>​I/O</​td><​td>​LDR left</​td><​td>​light dependent resistor input/​discharge</​td></​tr>​ +|I/O|LDR right|light dependent resistor input/​discharge| 
-  <​tr><​td>​I/O</​td><​td>​LDR right</​td><​td>​light dependent resistor input/​discharge</​td></​tr>​ +|O|LED|antenna LEDs on/off| 
-  <​tr><​td>​O</​td><​td>​LED</​td><​td>​antenna LEDs on/off</​td></​tr>​ +|O|motor 2a|motor forward/​reverse drivers, PWM lines?| 
-  <​tr><​td>​O</​td><​td>​motor 2a</​td><​td>​motor forward/​reverse drivers, PWM lines?</​td></​tr>​ +|O|motor 2b| - can not let both go low together as forms a short circuit| 
-  <​tr><​td>​O</​td><​td>​motor 2b</​td><​td>&​nbsp;&​nbsp;​can'​t ​let both go low together as forms a short circuit</​td></​tr>​ +|O|motor 1a|motor forward/​reverse drivers, PWM lines?| 
-  <​tr><​td>​O</​td><​td>​motor 1a</​td><​td>​motor forward/​reverse drivers, PWM lines?</​td></​tr>​ +|O|motor 1b| - can not let both go low together as forms a short circuit| 
-  <​tr><​td>​O</​td><​td>​motor 1b</​td><​td>&​nbsp;&​nbsp;​can'​t ​let both go low together as forms a short circuit</​td></​tr>​ +\\ 
-</​tbody></​table>​ +Sonar I/board:\\
-<br/>​Sonar ​board:<​br/>​ +
-<​table><​tbody>​ +
-  <​tr><​td width="​10%"><​b>​Direction</​b></​td><​td width="​10%"><​b>​Label</​b></​td><​td><​b>​Description</​b></​td></​tr>​ +
-  <​tr><​td>​O</​td><​td>​PZQ1</​td><​td>​outputs to drive ultrasonic transmitters</​td></​tr>​ +
-  <​tr><​td>​O</​td><​td>​PZQ2</​td><​td>&​nbsp;&​nbsp;​drive one high and one low at the same time, gives 10V across transducer</​td></​tr>​ +
-  <​tr><​td>​O</​td><​td>​gate 1</​td><​td>​select left/right receivers</​td></​tr>​ +
-  <​tr><​td>​O</​td><​td>​gate 2</​td><​td></​td></​tr>​ +
-  <​tr><​td>​I</​td><​td>​output</​td><​td>​received echo signal</​td></​tr>​ +
-</​tbody></​table>​ +
-</​HTML>​+
  
 +^Direction^Label^Description|
 +|O|PZ-01|outputs to drive ultrasonic transmitters|
 +|O|PZ-02| - drive one high and one low at the same time, gives 10V across transducer|
 +|O|gate1|select left/right receivers|
 +|O|gate2| |
 +|I|output|received echo signal|
 ===== Replacing the Cybot functions ===== ===== Replacing the Cybot functions =====
 ==== Arduino Sonar replacement ==== ==== Arduino Sonar replacement ====
 The most difficult controller function to replace appears to me to be the ultrasonic sensors. The hardware is fairly minimal and a lot of the work has to be done in software. The most difficult controller function to replace appears to me to be the ultrasonic sensors. The hardware is fairly minimal and a lot of the work has to be done in software.
  
-The Arduino has to generate the 40kHz, 10V p-p, driving signal for the two transmitters,​ then check for a received echo on the right and left receivers. The echo signal should provide range information as well as just presence/​absence of obstructions. The sensors face forward on an angle so don'​t ​actually tell you whether the detected object is forward or to the sides of the Cybot. If an object is directly ahead, and flat, both sensors should receive an equal signal that decreases in distance as the Cybot advances, but two converging walls on either side would produce a similar result.+The Arduino has to generate the 40kHz, 10V p-p, driving signal for the two transmitters,​ then check for a received echo on the right and left receivers. The echo signal should provide range information as well as just presence/​absence of obstructions. The sensors face forward on an angle so do not actually tell you whether the detected object is forward or to the sides of the Cybot. If an object is directly ahead, and flat, both sensors should receive an equal signal that decreases in distance as the Cybot advances, but two converging walls on either side would produce a similar result.
  
-I decided that the software echo detector should be interrupt driven, so that the Cybot can continue to maneuver ​etc, and have the sensors update independently. The output of the Cybot sonar board is a negative going pulse for each echo received. Looking at an oscilloscope I see many more echo pulses than wave cycles transmitted,​ I expect that the Cybot'​s pings are bouncing back and forth between the Cybot and the target, generating multiple echoes. The transmitter produces a broad pulse, so there are also multiple echoes from different ​direction ​and distances so there are groups of echoes returned. Difficult to interpret all the echoes, so we'​ll ​ignore all but the first pulse seen after sending our ping - that will give us the distance to the nearest object.+I decided that the software echo detector should be interrupt-driven, so that the Cybot can continue to manoeuvre ​etc, and have the sensors update independently. The output of the Cybot sonar board is a negative-going pulse for each echo received. Looking at an oscilloscope I see many more echo pulses than wave cycles transmitted,​ I expect that the Cybot'​s pings are bouncing back and forth between the Cybot and the target, generating multiple echoes. The transmitter produces a broad pulse, so there are also multiple echoes from different ​directions ​and distances so there are groups of echoes returned. Difficult to interpret all the echoes, so we will ignore all but the first pulse seen after sending our ping - that will give us the distance to the nearest object.
  
-{{arduino:​cybot:​P2117151a.JPG?350}} {{arduino:​cybot:​P2117153a.JPG?350}}+{{arduino:​cybot:​p2117151b.jpg?350}} {{arduino:​cybot:​p2117153b.jpg?350}}
  
 On the left is one of the sonar driver outputs (top trace) with the multiple echoes (bottom trace). On the right, on a longer time base, is again the sonar pulse (top trace), and multiple groups of echo from different objects (bottom trace) On the left is one of the sonar driver outputs (top trace) with the multiple echoes (bottom trace). On the right, on a longer time base, is again the sonar pulse (top trace), and multiple groups of echo from different objects (bottom trace)
Line 65: Line 61:
 ==== Arduino Sonar wiring ==== ==== Arduino Sonar wiring ====
 Tested by connecting the Arduino directly to the sonar board, supplying power to the Arduino and Sonar board via the USB connector. Tested by connecting the Arduino directly to the sonar board, supplying power to the Arduino and Sonar board via the USB connector.
 +
 +^Arduino^Direction^Cybot Board^^Description|
 +^Pin^ ^Sonar I/O Pin^^ |
 +|GND|-|13|GND|ground|
 +|+5V|-|11|+5V|power|
 +|6|O|6|PZ-01|outputs to drive ultrasonic transmitters|
 +|7|O|5|PZ-02|- drive one high and one low at the same time, gives 10V across transducer|
 +|2|I|4|output|received echo signal, to generate an interrupt|
 +|4|I/​O|3|gate1|select left/right receivers|
 +|5|I/​O|2|gate2|- disable by pulling low, enable by letting float (switch to input mode)|
 +
 +==== Arduino Sonar test code ====
 +
 +  * {{arduino:​cybot:​v1.00:​Cybot-sonar-test.ino}},​ sketch to test drive the Cybot'​s sonar board. ​ This is a stand-alone piece of code to test drive the sonar, it expects an ANSI serial terminal program is present to display the results.
 +
 +==== Arduino Sonar obstacle avoidance testing ====
 +  * {{arduino:​cybot:​v1.00:​cybot-motor-sonar-v1.06.ino|v1.06}} Sonar test of obstacle avoidance. ​ This is an expanded program with an interrupt-driven routine to handle the ultrasonic sensors. ​  It tries to steer the Cybot away from obstacles and detect whether it has become stalled.
  
 <​HTML>​ <​HTML>​
-<table><​tbody>​ +  ​<div class="shadows" ​style="text-align:​centermargin-left:​ auto;  ​margin-right:​ auto; "
-  <​tr><​td width="10%"><​b>​Arduino<​br/>​Pin</​b></​td><​td width="10%"><​b>​Direction</​b><​br/>&​nbsp;</​td><​td width="​10%"><​b>​Cybot<​br/>​Sonar Pin</​b></​td><​td><​b>​Description</​b><​br/>&​nbsp;</​td></​tr>​ +    <a href="/dokuwiki/_detail/arduino/cybot/dsc_0046a.jpg"​ class="​media"​><img src="/dokuwiki/_media/arduino/cybot/dsc_0046a.jpg"​ width="​90%"​ class="​media"​ title="​Cybot side view" alt="​Cybot with Arduino UNO" ​/></a
-  <​tr><​td>​2</​td><​td>​I</​td><​td>​4 output</​td><​td>​received echo signal, to generate an interrupt</​td></​tr+    <div class="​container"​
-  <​tr><​td>​4</td><​td>​I/O</td><​td>​3 gate-1</td><​td>​select left/right receivers</​td></tr> +      Cybot fitted with Arduino UNO controller ​and LCD display 
-  <​tr><​td>​5<​/td><​td>​I/O</td><​td>​2 gate-2</td><​td>&​nbsp;&​nbsp;​disable by pulling low, enable by letting float (switch to input mode)</td></tr+    </div
-  <tr><​td>​6</​td><​td>​O</​td><​td>​6 PZQ1</​td><​td>​outputs to drive ultrasonic transmitters</​td></​tr+  </div>
-  <​tr><​td>​7</​td><​td>​O</​td><​td>​5 PZQ2</​td><​td>&​nbsp;&​nbsp;​drive one high and one low at the same time, gives 10V across transducer</​td></​tr>​ +
-  <​tr><​td>​+5V</td><​td>​-</​td><​td>​11 +5V</​td><​td>​power</​td></​tr+
-  ​<​tr><​td>​GND</​td><​td>​-</​td><​td>​13 GND</​td><​td>​ground</​td></​tr>​ +
-</​tbody>​</table>+
 </​HTML>​ </​HTML>​
  
-==== Arduino Sonar test code ==== +{{ arduino:​cybot:​v1.00:​cybot_arduino_schem.png?​600 |Arduino to Cybot connections}}
-This is a stand alone piece of code to test drive the sonar, it expects an ANSI serial terminal program is present to display the results. +
-{{arduino:​cybot:​v1.00:​Cybot-sonar-test.ino}}, sketch to test drive the Cybots sonar board.+
  
-Library+Test drive of Cybot showing it sometimes avoiding hard surfaces, sometimes crashing into them.  Also shows stall detection when it runs into an edge that the angled front sonar detectors can not see - after 20 seconds it decides it is stalled, and restarts. (NB in this test the front wheel is tending to veer right so the Cybot does not travel in straight lines).
  
-.+<​HTML>​ 
 +  <div class="​shadows"​ style="​text-align:​center">​ 
 +    <video width="​640" ​ controls>​ 
 +      <source src="/​dokuwiki/​_media/​arduino/​cybot/​v1.00/​p1269362b.mp4"​ type="​video/​mp4">​ 
 +Your browser does not support the video tag. 
 +    </​video>​ 
 +    <div class="​container">​ 
 +      Test drive of Arduino controlled Cybot 
 +    </​div>​ 
 +  </​div>​ 
 +</​HTML>​
  
 +My main problem was detecting when the Cybot had got itself into trouble and was not moving. ​ I tried looking at whether the sonar echos were unchanging - indicating it was not moving (or there was a very uniform environment),​ but there was too much "​noise",​ natural variability,​ in the returned echos to tell the difference. ​ Of course there are lots of ways involving adding extra sensors (eg wheel rotation detectors) to detect whether it was stalled, but adding them would be going against the plan of trying to make the best Cybot using the current hardware, but just replacing the brains. ​  I did add a voltage divider to monitor the battery level using an Arduino analog input - when stalled the Cybot draws a lot of current and because of the batteries internal resistance, the voltage drops. ​ While not actually adding another active sensor device, this is cheating a little. ​  Not 100% successful as on smooth surfaces the Cybot'​s wheels just spin when it is stalled, so the current peek is not as high.
  
-==== The programs==== +For testing purposes the Arduino was fitted with an LCD display so that I could monitor what the code was seeing, and what it "​thought"​ its current state was (eg running, turning, stalled). ​ This version monitors current speed, battery voltage, and the left and right sonar return levels. 
-  ​.+ 
 + 
 +{{arduino:cybot:​v1.00:​dsc_0050b.jpg?​400|Cybot LCD status display}} 
 + 
 +I had also tried feeding this information back to my desktop PC via the serial cable, including operating an onboard ring buffer log which could be played back when the Cybot was again connected to the computer'​s USB port.  But all these approaches have their limitations,​ perhaps I need to go for a wireless real-time communication channel, eg infrared, Bluetooth, or WiFi, combined with a video record of what the Cybot was seen to be doing at the time.
  
 ====== References and Additional Resources ====== ====== References and Additional Resources ======
 +===== Cybot Sonar =====
 +     * [[https://​web.archive.org/​web/​20170530184650/​http://​www.cybench.co.uk/​cybot/​sonar.php|Cybot sonar circuit analysis]]
 +     * [[http://​www.adrirobot.it/​cybot/​cybot/​sonar_io/​sonar_io.htm|Cybot sonar circuit, Italian]]
 +     * [[http://​www.lpilsley.co.uk//​cybot/​sonario.htm|Cybot sonar circuit description]]
 +
 ===== Cybot builders ===== ===== Cybot builders =====
  
-     * [[https://​web.archive.org/​web/​20161221164000/​http://​www.lpilsley.co.uk:​80/​cybot/​index.htm|A Cybot Technical Site by Nigel Goodwin]].+     * [[http://​www.lpilsley.co.uk:​80/​cybot/​index.htm|A Cybot Technical Site by Nigel Goodwin]]. 
 +         * [[http://​lpilsley.co.uk/​cybot/​radar.htm|IR Obstacle Detector Board]]
      * Forum: Microcontroller and Digital Electronics,​ AT MEGA 163 ([[https://​www.mikrocontroller.net/​topic/​2486|German]],​ [[https://​www.mikrocontroller.net/​topic/​2486|English]])      * Forum: Microcontroller and Digital Electronics,​ AT MEGA 163 ([[https://​www.mikrocontroller.net/​topic/​2486|German]],​ [[https://​www.mikrocontroller.net/​topic/​2486|English]])
        * [[https://​www.mikrocontroller.net/​attachment/​683/​komplett.gif|Cybot schematic]]{{:​arduino:​cybot:​komplett.gif?​1| }}.        * [[https://​www.mikrocontroller.net/​attachment/​683/​komplett.gif|Cybot schematic]]{{:​arduino:​cybot:​komplett.gif?​1| }}.
-     * [[http://​www.adrirobot.it/​menu_new/​index/​index_cybot.htm|Adrirobot Cybot Presentazione]]. (Italian site with built in translation option).+     * [[http://​www.adrirobot.it/​menu_new/​index/​index_cybot.htm|Adrirobot Cybot Presentazione]]. (Italian site with built-in translation option).
        * [[http://​www.adrirobot.it/​menu_new/​index/​index_cybot_telecomando.htm|Cybot remote control]].        * [[http://​www.adrirobot.it/​menu_new/​index/​index_cybot_telecomando.htm|Cybot remote control]].
-     * [[http://​hobbyelectronica.hol.es/​|Electronica als hobby]]. (Dutch site, but built in translation links).+     * [[http://​hobbyelectronica.hol.es/​|Electronica als hobby]]. (Dutch site, but built-in translation links).
      * [[https://​web.archive.org/​web/​20121010142548/​http://​www.mstracey.btinternet.co.uk/​|Mike'​s Cybot Page]].      * [[https://​web.archive.org/​web/​20121010142548/​http://​www.mstracey.btinternet.co.uk/​|Mike'​s Cybot Page]].
      * [[https://​web.archive.org/​web/​20080821101139/​http://​www.cybench.co.uk/​index.php|Robotics,​ Cybot and Electronics Resources]].      * [[https://​web.archive.org/​web/​20080821101139/​http://​www.cybench.co.uk/​index.php|Robotics,​ Cybot and Electronics Resources]].
Line 117: Line 145:
      * [[https://​www.youtube.com/​watch?​v=MqYYqw0RPKc|Cybot Upgrade]].\\ Cybot internals replaced with Arduino Uno, follows light based on LDR readings ({{arduino:​cybot:​cybot_ldr_light_follower.c|the code}}).\\      * [[https://​www.youtube.com/​watch?​v=MqYYqw0RPKc|Cybot Upgrade]].\\ Cybot internals replaced with Arduino Uno, follows light based on LDR readings ({{arduino:​cybot:​cybot_ldr_light_follower.c|the code}}).\\
      * [[https://​web.archive.org/​web/​20060925083315/​http://​linbot.sourceforge.net/​index.html|Linbot]] (also [[http://​www.ouroboros.org/​linbot/​index.html|new site]]) by Ricardo Tellez.\\ Start of project to control Cybot from Linux.\\      * [[https://​web.archive.org/​web/​20060925083315/​http://​linbot.sourceforge.net/​index.html|Linbot]] (also [[http://​www.ouroboros.org/​linbot/​index.html|new site]]) by Ricardo Tellez.\\ Start of project to control Cybot from Linux.\\
-     * [[https://​github.com/​XarpeSerpe/​cybot|gitub XarpeSerpe'​s Cybot]] (French).\\ Control firmware for a cybot replacing its processors with an arduino.\\+     * [[https://​github.com/​XarpeSerpe/​cybot|gitub XarpeSerpe'​s Cybot]] (French).\\ Control firmware for a Cybot replacing its processors with an Arduino.\\
      * [[https://​github.com/​fitzterra/​Cybot|github Fitzterra'​s Cybot]].\\ Cybot Resurrected - Arduino based Cybot re-engineered.\\      * [[https://​github.com/​fitzterra/​Cybot|github Fitzterra'​s Cybot]].\\ Cybot Resurrected - Arduino based Cybot re-engineered.\\
      * [[https://​github.com/​djneo92nl/​cybot|github Djneo92nl'​s Cybot]].\\ Cybot (cheap toy) arduino driver.\\      * [[https://​github.com/​djneo92nl/​cybot|github Djneo92nl'​s Cybot]].\\ Cybot (cheap toy) arduino driver.\\
Line 132: Line 160:
 \\ \\
 ---- ----
-<​html><​div style="​width:​ 80%; text-align:​center">&​nbsp;</​html>​[[:​start|Home Page]]<​html>&​nbsp;&​nbsp;&​nbsp;</​html>​[[:​about|About this Site]]<​html>&​nbsp;&​nbsp;&​nbsp;</​html>​[[:​copyright|Copyright Questions]]<​html>&​nbsp;&​nbsp;&​nbsp;</​html>​[[:​contact|Contact Us]]<​html>&​nbsp;&​nbsp;&​nbsp;</​html>​[[:​robotic:​resources|Resources]]<​html></​div></​html>​\\+<​html><​div style="​width:​ 80%; text-align:​center">&​nbsp;</​html>​[[:​start|Home Page]]<​html>&​nbsp;&​nbsp;&​nbsp;</​html>​[[:​about|About this Site]]<​html>&​nbsp;&​nbsp;&​nbsp;</​html>​[[:​copyright|Copyright Questions]]<​html>&​nbsp;&​nbsp;&​nbsp;</​html>​[[:​contact|Contact Us]]<​html></​div></​html>​\\
 \\ \\