Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.
/ Zumo---Sonar Public archive

Ultrasound sonar driver for HC-SR04 and Power HD 1160A Servo

Notifications You must be signed in to change notification settings

kmaslows/Zumo---Sonar

Repository files navigation

Zumo Sonar Library

Sonar library for Project Lab
Zumol
Doxygen Documentation

Features

  • Control of HC-SR04 Sonar
  • Control of Power HD 1160A Servo
  • Many work modes
    • Constant measurement at fixed position
    • Constant measurement in two different sweep modes
    • Single measurement at given angles using interupts and polling
  • Support for averaging of measurements
  • Pseudo feedback for servo.
  • Labview interface

Setup - hardware

Connect sonar and servo pins as follows:

Sonar:

  • PTE20 <-> Sonar Echo pin
  • PTE21 <-> Sonar Trigger pin
  • 5V <-> Sonar Vcc
  • Gnd <-> Sonar Gnd

We recommend using voltage divider on Echo pin
Divider

Servo:

  • PTE22 <-> Servo Yellow cable
  • 5V <-> Servo Red Cable
  • Gnd <-> Servo Brown Cable

We recommend connecting 470uF capacitor near Servo power connectors.

Setup - software

  1. Copy sonar.h, sonar.c, servo.c and servo.h files to your project.

  2. Include both headers in your main.c file

    #include "sonar.h"
    #include "servo.h"
  3. In your main function initialize Sonar anf Servo with proper options.

int main(void){
	Sonar_init(SINGLE);
	Servo_init(MANUAL, SCAN_AND_GO);
	(...)
}

Check documentation for details: Servo_init() and Sonar_init().

  1. Decide how you want to retrieve measurements results

    • Via Interupt (Both Single and Sweep measurements modes) In sonar.c file at the bottom, there is a function called SonarDistHandler. This function is called when Sonar obtains some usable data. For example if you want to send the results you can use it like this: To trigger measurement you can use CONTINUOUS Sonar mode or SonarStartMeas function.

       void SonarDistHandler(uint16_t distance_cm, int32_t angle){	
       	/* Your code here */
       	char buffor[12];
       	sprintf(buffor, "%04d,%04hu\n",angle,distance_cm);
       	bt_sendStr(buffor);
       }	
    • Via Pooling If you just want to easly get single measurement, use SonarGetDistance function somewhere in your code. For example, to get distance measurement at angle 45deg use

       int result = SonarGetDistance(new_deg);
  2. Change Sonar and Servo work modes during runtime if needed. You should only use these functions for this purpose. Do NOT modify the content of any Servo or Sonar variables by hand!

  3. In sonar.h and servo.h there are few parameters which can be changed, depending on needs. For example, how many samples to average or measurement interval in continous mode. Before you try and modyfy any of them, read the comments!

Work modes

There are sevral work modes available.

Single measurements

The easiest way to get distance is to use SonarGetDistance or SonarStartMeas function. Difference between those two funtions is simple: The first one will constantly pool the Sonar until it retrieves the result. Not very efficient, but very simple to use. The second one will trigger a measurement and exit. When Sonar gets the result, it will trigger SonarDistHandler.

Continuous measurement

If you want to get a steady stream of measurements, use Sonar in CONTINUOUS mode. Use SonarDistHandler to retrieve data. If you want to change sonar position, use ServoMoveByDegree. Remember to set Servo to manual mode first!

Sweep modes

There are two Sweep modes available:

  • Sweep and Go Sonar will move constantly by angle defined by SERVO_STEP_DEG. At each step it will try to measure the distance and return the result via SonarDistHandler.
  • Sweep and Lock Sonar will move until it finds something closer than ServoLockRange. You can change this value using ServoChangeLockRange function. When the lock is lost, servo will resume sweep until it locks again.

Labview interface

We created an intreface for testing sonar. LINK - EXE.
Control Panel
**Note: It requires bluetooth module to work. If you need labview files, send us an email.

About

Ultrasound sonar driver for HC-SR04 and Power HD 1160A Servo

Resources

Stars

Watchers

Forks

Packages

No packages published