Page 1 of 1

HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Fri Sep 14, 2018 8:28 am
by admin
Image





This Arduino compatible library has been written specifically for the Hobby Components Obstacle Avoidance Robot Car Kit (HCKITS0060). It is used the demo sketch shipped with the kit and also provides an easy means of controlling the robot car using your own sketches. The library includes functions for controlling the robot cars motors and for taking reading from the ultrasonic sensor.

You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.

On Windows:
My Documents\Arduino\libraries\

On Mac:
Documents/Arduino/libraries/

Linux:
Usually found within the users home area under /Arduino/libraries/



Using the HCOARC library

To use the library just include the HCOARC.h header file and then create an instance of the library. E.g:
  1. #include "HCOARC.h"
  2. HCOARC HCOARC;

To initialise the library place the following line in the Setup() loop at the top of the sketch:
  1. HCMotor.Init();


The following functions are available with this library:

  1. void Attach(MotorNum,  PinA,  PinB);
Attaches a PWM output for a standard DC motor where:
MotorNum is a value used to reference which motor you wish to attach. Valid values are:

LEFT_MOTOR - Attach the left motor (motor 0)
RIGHT_MOTOR - Attach the right motor (motor 1)

PinA is the digital pin number connected to INA of the H-Bride module.
PinB is the digital pin number connected to INB of the H-Bride module.


  1. void Detach(MotorNum);
Removes an attached motor from the list and sets its pin(s) to inputs where:

MotorNum the motor you wish to detach. Valid values are:
LEFT_MOTOR - Detach the left motor (motor 0)
RIGHT_MOTOR - Detach the right motor (motor 1)


  1. void Speed(MotorNum, Percent);
Sets the speed of one of the connected motors in % where:

MotorNum is the motor you wish to change the speed for. Valid values are:
LEFT_MOTOR - Change the speed for the left motor
RIGHT_MOTOR - Change the speed for the right motor

Percent is the motor speed specified in percent where 0 - full stop and 100 is full speed.



  1. void Direction(MotorNum, Direction);   
Sets the rotational direction of one of the connected motors where:

MotorNum is the motor you wish to change the speed for. Valid values are:
LEFT_MOTOR - Change the direction for the left motor
RIGHT_MOTOR - Change the direction for the right motor

Direction is the rotational direction. Valida values are
FORWARD - Motor will rotate in the forward direction.
REVERSE - Motor will rotate in the reverse direction.



  1. void Ultrasonic_Init(Echo, Trig);
Starts repeated measurements of the ultrasonic sensor where:

Echo is the digital pin number connected to the Echo pin on the sensor.
Trig is the digital pin number connected to the Trig pin on the sensor.



  1. void Ultrasonic_Init(Echo, Trig);
Starts repeated measurements of the ultrasonic sensor where:

Echo is the digital pin number connected to the Echo pin on the sensor.
Trig is the digital pin number connected to the Trig pin on the sensor.



  1. void Ultrasonic_Init(Power, Gnd, Echo, Trig);  
Starts repeated measurements of the ultrasonic sensor where:

Power is the digital pin number connected to the Power pin on the sensor.
Gnd is the digital pin number connected to the Gnd pin on the sensor.
Echo is the digital pin number connected to the Echo pin on the sensor.
Trig is the digital pin number connected to the Trig pin on the sensor.



  1. volatile uint8_t Ultrasonic_Raw(void);
Returns a raw distance measurement from the ultrasonic sensor measured in
100us ticks as type Byte,




Image

  1. /* FILE:    OARC_Example.h
  2.    DATE:    13/09/18
  3.    VERSION: 0.1
  4.    AUTHOR:  Andrew Davies
  5.    
  6. 13/09/18 version 0.1: Original version
  7.  
  8. This is the demo sketch which is pre-flashed into the Nano shipped in the
  9. Hobby Components Obsicle Avoidance Robot Car Kit (HCKITS0060). The sketch is
  10. provided as an example of how to use the HCOARC library created specifically for this
  11. kit. You can find more information about this library on our support forum here:
  12.  
  13. HTTPS://HOBBYCOMPONENTS.COM/OARC
  14.  
  15. You may copy, alter and reuse this code in any way you like, but please leave
  16. reference to HobbyComponents.com in your comments if you redistribute this code.
  17. This software may not be used directly for the purpose of selling products that
  18. directly compete with Hobby Components Ltd's own range of products.
  19. THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
  20. EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  21. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
  22. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
  23. INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
  24. REASON WHATSOEVER.
  25. */
  26.  
  27. #include "HCOARC.h"
  28.  
  29. HCOARC HCOARC;
  30.  
  31. #define LED_PIN 13
  32.  
  33. void setup()
  34. {
  35.   HCOARC.Init();
  36.   HCOARC.Ultrasonic_Init(A2, A5, A4, A3);
  37.  
  38.   HCOARC.Attach(LEFT_MOTOR, 2, 3);
  39.   HCOARC.Attach(RIGHT_MOTOR, 4, 5);
  40.  
  41.   pinMode(LED_PIN, OUTPUT);
  42.  
  43.   for(byte i = 0; i < 5; i++)
  44.   {
  45.     delay(500);
  46.     digitalWrite(LED_PIN, HIGH);
  47.     delay(500);
  48.     digitalWrite(LED_PIN, LOW);
  49.   }
  50.  
  51.   HCOARC.Speed(LEFT_MOTOR, 100);
  52.   HCOARC.Speed(RIGHT_MOTOR, 100);
  53. }
  54.  
  55.  
  56.  
  57. void loop()
  58. {
  59.   byte Distance = HCOARC.Ultrasonic_Raw();
  60.  
  61.   if(Distance >= 25)
  62.   {
  63.     HCOARC.Direction(LEFT_MOTOR, FORWARD);
  64.     HCOARC.Direction(RIGHT_MOTOR, FORWARD);
  65.   }else
  66.   {
  67.     digitalWrite(LED_PIN, HIGH);
  68.     HCOARC.Direction(LEFT_MOTOR, REVERSE);
  69.     HCOARC.Direction(RIGHT_MOTOR, FORWARD);
  70.  
  71.     delay(100);
  72.     digitalWrite(LED_PIN, LOW);
  73.   }
  74. }


Image

HCOARC.zip



Disclaimer: Libraries, example code, and diagrams are provided as an additional free service by Hobby Components and are not sold as part of this product. We do not provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.

Re: HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Tue Oct 02, 2018 2:00 pm
by mmcp42
link for the library hcoarc.zip seems to be broken :(

Re: HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Tue Oct 02, 2018 2:21 pm
by andrew
I've just checked it and it seems to be working fine for me. Where you logged in when you tried to download it?

Re: HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Tue Oct 02, 2018 2:39 pm
by mmcp42
andrew wrote:
Tue Oct 02, 2018 2:21 pm
I've just checked it and it seems to be working fine for me. Where you logged in when you tried to download it?
yup

https://forum.hobbycomponents.com/downl ... php?id=554

I get "can't establish a secure connection to forum.hobbycomponents.com"
tried with several browsers, and tried with http instead of https
no joy :(

Re: HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Tue Oct 02, 2018 2:43 pm
by mmcp42
PS
I tried a few other libraries (from other threads)
got the same, sorry

Re: HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Tue Oct 02, 2018 2:45 pm
by admin
Can you try it without the https:


download/file.php?id=554

Re: HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Tue Oct 02, 2018 2:59 pm
by mmcp42
added HobbyComponents.com to avast "exclusions" list
now downloaded :)

Re: HCOARC Arduino library for Obstacle Avoidance Robot Car Kit

Posted: Tue Oct 02, 2018 3:04 pm
by andrew
Ah ok, glad you managed to fix it. Not seen that issue before but interesting to know an AV (Avast at least) can interfere with the downloads on this forum. I'll keep it in mind in case anybody else has the same problem.