Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: vl53l0x_api SRF05
Revision 0:041c1089b6e5, committed 2022-03-10
- Comitter:
- dnikolz
- Date:
- Thu Mar 10 08:40:14 2022 +0000
- Commit message:
- idk
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Thu Mar 10 08:40:14 2022 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CONTRIBUTING.md Thu Mar 10 08:40:14 2022 +0000 @@ -0,0 +1,5 @@ +# Contributing to Mbed OS + +Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor. + +To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Thu Mar 10 08:40:14 2022 +0000 @@ -0,0 +1,64 @@ + +# Blinky Mbed OS example + +The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/) and is the [getting started example for Mbed OS](https://os.mbed.com/docs/mbed-os/v5.14/quick-start/index.html). It contains an application that repeatedly blinks an LED on supported [Mbed boards](https://os.mbed.com/platforms/). + +You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). +(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).) + +1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html). + +1. Clone this repository on your system, and change the current directory to where the project was cloned: + + ```bash + $ git clone git@github.com:armmbed/mbed-os-example-blinky && cd mbed-os-example-blinky + ``` + + Alternatively, you can download the example project with Arm Mbed CLI using the `import` subcommand: + + ```bash + $ mbed import mbed-os-example-blinky && cd mbed-os-example-blinky + ``` + + +## Application functionality + +The `main()` function is the single thread in the application. It toggles the state of a digital output connected to an LED on the board. + +## Building and running + +1. Connect a USB cable between the USB port on the board and the host computer. +2. <a name="build_cmd"></a> Run the following command to build the example project and program the microcontroller flash memory: + ```bash + $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash + ``` +The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin`. + +Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB. + +Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target: + +```bash +$ mbed compile -S +``` + +## Expected output +The LED on your target turns on and off every 500 milliseconds. + + +## Troubleshooting +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it. + +## Related Links + +* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html). +* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html). +* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html). +* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html). +* [Mbed boards](https://os.mbed.com/platforms/). + +### License and contributions + +The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info. + +This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SRF05.lib Thu Mar 10 08:40:14 2022 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/SRF05/#e758665e072c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Simplifier/Shape.cpp Thu Mar 10 08:40:14 2022 +0000
@@ -0,0 +1,38 @@
+#define Pin1 PB_0
+#define Pin2 PB_0
+#define Pin_GPIO PB_0
+//DigitalOut myled(LED1);
+#include "mbed.h"
+#include "Shape.h"
+
+PwmOut Drive_pin_A2(PA_8); //steering servo PWM output pin D7
+PwmOut Drive_pin_B2(PA_9); //Not Used
+PwmOut Drive_pin_C2(PB_10); //Motor drive PWM output pin D6
+PwmOut Drive_pin_D2(PB_4); //Motor drive PWM output pin D5
+
+int Turn_right3=2;
+int Turn_left3=0;
+int Speed13=10; //Half power
+int Speed23=20; //Full power
+int PW_Period3=20;
+
+ void Shape::oval(){
+ Turn_left3 = 1775; // half turn left - end point
+ Turn_left3 = 1770;
+ wait_us(1);
+ Drive_pin_A2.pulsewidth_us(Turn_left3);
+ Turn_left3 = 1775;
+ wait_us(1);
+ Turn_left3 = 1625;
+ Drive_pin_A2.pulsewidth_us(Turn_left3);
+ Turn_left3 = 1770;
+ wait_us(1);
+ Drive_pin_A2.pulsewidth_us(Turn_left3);
+ Turn_left3 = 1775;
+ wait_us(1);
+ Turn_left3 = 1625;
+ Drive_pin_A2.pulsewidth_us(Turn_left3);
+ Turn_left3 = 1770;
+ wait_us(1);
+ Drive_pin_A2.pulsewidth_us(Turn_left3);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Simplifier/Shape.h Thu Mar 10 08:40:14 2022 +0000
@@ -0,0 +1,4 @@
+class Shape {
+public:
+ static void oval();
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Simplifier/Simplifier.cpp Thu Mar 10 08:40:14 2022 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"
+#include "vl53l0x_api.h"
+#include "vl53l0x_platform.h"
+#include "vl53l0x_i2c_platform.h"
+#include "SRF05.h"
+#include "Simplifier.h"
+
+#define Pin1 PB_0
+#define Pin2 PB_0
+#define Pin_GPIO PB_0
+
+SRF05 _distCam(Pin1 ,Pin1); // FRONT-END
+
+void Simplifier::accelerator(){
+ float fz = _distCam.read();
+}
+void speedometer(){}
+
+void Simplifier::runWorker() {
+
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Simplifier/Simplifier.h Thu Mar 10 08:40:14 2022 +0000
@@ -0,0 +1,12 @@
+#include "vl53l0x_api.h"
+#include "vl53l0x_platform.h"
+#include "vl53l0x_i2c_platform.h"
+class Simplifier {
+public:
+ void runWorker();
+ void speedometer();
+ static void accelerator();
+ void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData);
+
+
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Simplifier/VL53L0XSimplifier.cpp Thu Mar 10 08:40:14 2022 +0000
@@ -0,0 +1,252 @@
+#include "mbed.h"
+#include "vl53l0x_api.h"
+#include "vl53l0x_platform.h"
+#include "vl53l0x_i2c_platform.h"
+#include "VL53L0XSimplifier.h"
+//CAMERA SENSOR 1FT
+Serial pc(SERIAL_TX, SERIAL_RX);
+
+void VL53Simplifier::print_pal_error(VL53L0X_Error Status){
+ char buf[VL53L0X_MAX_STRING_LENGTH];
+ VL53L0X_GetPalErrorString(Status, buf);
+ printf("API Status: %i : %s\n", Status, buf);
+}
+
+VL53L0X_Error VL53Simplifier::WaitMeasurementDataReady(VL53L0X_DEV Dev) {
+ VL53L0X_Error Status = VL53L0X_ERROR_NONE;
+ uint8_t NewDatReady=0;
+ uint32_t LoopNb;
+
+ // Wait until it finished
+ // use timeout to avoid deadlock
+ if (Status == VL53L0X_ERROR_NONE) {
+ LoopNb = 0;
+ do {
+ Status = VL53L0X_GetMeasurementDataReady(Dev, &NewDatReady);
+ if ((NewDatReady == 0x01) || Status != VL53L0X_ERROR_NONE) {
+ break;
+ }
+ LoopNb = LoopNb + 1;
+ VL53L0X_PollingDelay(Dev);
+ } while (LoopNb < VL53L0X_DEFAULT_MAX_LOOP);
+
+ if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP) {
+ Status = VL53L0X_ERROR_TIME_OUT;
+ }
+ }
+
+ return Status;
+}
+
+
+VL53L0X_Error VL53Simplifier::WaitStopCompleted(VL53L0X_DEV Dev) {
+ VL53L0X_Error Status = VL53L0X_ERROR_NONE;
+ uint32_t StopCompleted=0;
+ uint32_t LoopNb;
+
+ // Wait until it finished
+ // use timeout to avoid deadlock
+ if (Status == VL53L0X_ERROR_NONE) {
+ LoopNb = 0;
+ do {
+ Status = VL53L0X_GetStopCompletedStatus(Dev, &StopCompleted);
+ if ((StopCompleted == 0x00) || Status != VL53L0X_ERROR_NONE) {
+ break;
+ }
+ LoopNb = LoopNb + 1;
+ VL53L0X_PollingDelay(Dev);
+ } while (LoopNb < VL53L0X_DEFAULT_MAX_LOOP);
+
+ if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP) {
+ Status = VL53L0X_ERROR_TIME_OUT;
+ }
+
+ }
+
+ return Status;
+}
+void VL53Simplifier::print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData){
+ char buf[VL53L0X_MAX_STRING_LENGTH];
+ uint8_t RangeStatus;
+
+ /*
+ * New Range Status: data is valid when pRangingMeasurementData->RangeStatus = 0
+ */
+
+ RangeStatus = pRangingMeasurementData->RangeStatus;
+
+ VL53L0X_GetRangeStatusString(RangeStatus, buf);
+ printf("Range Status: %i : %s\n", RangeStatus, buf);
+
+}
+void VL53Simplifier::runVL53() {
+ // sensor camera
+
+ VL53L0X_Error Status = VL53L0X_ERROR_NONE;
+ VL53L0X_Dev_t MyDevice;
+ VL53L0X_Dev_t *pMyDevice = &MyDevice;
+ VL53L0X_Version_t Version;
+ VL53L0X_Version_t *pVersion = &Version;
+ VL53L0X_DeviceInfo_t DeviceInfo;
+
+ int32_t status_int;
+
+ pc.printf("VL53L0X API Simple Ranging Example\r\n");
+
+ // Initialize Comms
+ pMyDevice->I2cDevAddr = 0x52;
+ pMyDevice->comms_type = 1;
+ pMyDevice->comms_speed_khz = 400;
+
+ pc.printf("Init comms\r\n");
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ status_int = VL53L0X_GetVersion(pVersion);
+ if (status_int != 0)
+ Status = VL53L0X_ERROR_CONTROL_INTERFACE;
+ }
+ pc.printf("VL53L0X API Version: %d.%d.%d (revision %d)\r\n", pVersion->major, pVersion->minor ,pVersion->build, pVersion->revision);
+
+ int addr;
+
+ addr = VL53L0X_scan();
+ printf("Device found at: %i\r\n", addr);
+ //uint8_t data;
+ //data=0;
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Call of VL53L0X_DataInit\n");
+ uint16_t osc_calibrate_val=0;
+ Status = VL53L0X_RdWord(&MyDevice, VL53L0X_REG_OSC_CALIBRATE_VAL,&osc_calibrate_val);
+ printf("%i\n",osc_calibrate_val);
+ Status = VL53L0X_DataInit(&MyDevice); // Data initialization
+ VL53Simplifier::print_pal_error(Status);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ Status = VL53L0X_GetDeviceInfo(&MyDevice, &DeviceInfo);
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf("VL53L0X_GetDeviceInfo:\n");
+ printf("Device Name : %s\n", DeviceInfo.Name);
+ printf("Device Type : %s\n", DeviceInfo.Type);
+ printf("Device ID : %s\n", DeviceInfo.ProductId);
+ printf("ProductRevisionMajor : %d\n", DeviceInfo.ProductRevisionMajor);
+ printf("ProductRevisionMinor : %d\n", DeviceInfo.ProductRevisionMinor);
+
+ if ((DeviceInfo.ProductRevisionMinor != 1) && (DeviceInfo.ProductRevisionMinor != 1)) {
+ printf("Error expected cut 1.1 but found cut %d.%d\n",
+ DeviceInfo.ProductRevisionMajor, DeviceInfo.ProductRevisionMinor);
+ Status = VL53L0X_ERROR_NOT_SUPPORTED;
+ }
+ }
+ VL53Simplifier::print_pal_error(Status);
+ }
+
+ VL53L0X_RangingMeasurementData_t RangingMeasurementData;
+ VL53L0X_RangingMeasurementData_t *pRangingMeasurementData = &RangingMeasurementData;
+ Status = VL53L0X_ERROR_NONE;
+ uint32_t refSpadCount;
+ uint8_t isApertureSpads;
+ uint8_t VhvSettings;
+ uint8_t PhaseCal;
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Call of VL53L0X_StaticInit\n");
+ Status = VL53L0X_StaticInit(pMyDevice); // Device Initialization
+ // StaticInit will set interrupt by default
+ VL53Simplifier::print_pal_error(Status);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Call of VL53L0X_PerformRefCalibration\n");
+ Status = VL53L0X_PerformRefCalibration(pMyDevice,
+ &VhvSettings, &PhaseCal); // Device Initialization
+ VL53Simplifier::print_pal_error(Status);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Call of VL53L0X_PerformRefSpadManagement\n");
+ Status = VL53L0X_PerformRefSpadManagement(pMyDevice,
+ &refSpadCount, &isApertureSpads); // Device Initialization
+ VL53Simplifier::print_pal_error(Status);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+
+ printf ("Call of VL53L0X_SetDeviceMode\n");
+ Status = VL53L0X_SetDeviceMode(pMyDevice, VL53L0X_DEVICEMODE_CONTINUOUS_RANGING); // Setup in single ranging mode
+ VL53Simplifier::print_pal_error(Status);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Call of VL53L0X_StartMeasurement\n");
+ Status = VL53L0X_StartMeasurement(pMyDevice);
+ VL53Simplifier::print_pal_error(Status);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ uint32_t measurement;
+ uint32_t no_of_measurements = 32;
+
+ uint16_t* pResults = (uint16_t*)malloc(sizeof(uint16_t) * no_of_measurements);
+
+ for(measurement=0; measurement<no_of_measurements; measurement++)
+ {
+
+ Status = VL53Simplifier::WaitMeasurementDataReady(pMyDevice);
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ Status = VL53L0X_GetRangingMeasurementData(pMyDevice, pRangingMeasurementData);
+
+ *(pResults + measurement) = pRangingMeasurementData->RangeMilliMeter;
+ printf("In loop measurement %lu: %d\n", measurement, pRangingMeasurementData->RangeMilliMeter);
+
+ // Clear the interrupt
+ VL53L0X_ClearInterruptMask(pMyDevice, VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+ VL53L0X_PollingDelay(pMyDevice);
+ } else {
+ break;
+ }
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ for(measurement=0; measurement<no_of_measurements; measurement++)
+ {
+ printf("measurement %lu: %d\n", measurement, *(pResults + measurement));
+ }
+ }
+
+ free(pResults);
+ }
+
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Call of VL53L0X_StopMeasurement\n");
+ Status = VL53L0X_StopMeasurement(pMyDevice);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ {
+ printf ("Wait Stop to be competed\n");
+ Status = VL53Simplifier::WaitStopCompleted(pMyDevice);
+ }
+
+ if(Status == VL53L0X_ERROR_NONE)
+ Status = VL53L0X_ClearInterruptMask(pMyDevice,
+ VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY);
+ while (true)
+ if (pc.readable())
+ pc.putc(pc.getc());
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Simplifier/VL53L0XSimplifier.h Thu Mar 10 08:40:14 2022 +0000
@@ -0,0 +1,10 @@
+class VL53Simplifier {
+public:
+ static void runVL53();
+ void speedometer();
+ void accelerator();
+ static void print_pal_error(VL53L0X_Error Status);
+ static VL53L0X_Error WaitMeasurementDataReady(VL53L0X_DEV Dev);
+ static VL53L0X_Error WaitStopCompleted(VL53L0X_DEV Dev);
+ void print_range_status(VL53L0X_RangingMeasurementData_t* pRangingMeasurementData);
+};
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Mar 10 08:40:14 2022 +0000
@@ -0,0 +1,83 @@
+#include "mbed.h"
+#include "SRF05.h"
+#include "Simplifier.h"
+#include "Shape.h"
+#include "VL53L0XSimplifier.h"
+
+#define Pin1 PB_0
+#define Pin2 PB_0
+#define Pin_GPIO PB_0
+//DigitalOut myled(LED1);
+
+PwmOut Drive_pin_A(PA_8); //steering servo PWM output pin D7
+PwmOut Drive_pin_B(PA_9); //Not Used
+PwmOut Drive_pin_C(PB_10); //Motor drive PWM output pin D6
+PwmOut Drive_pin_D(PB_4); //Motor drive PWM output pin D5
+
+int Turn_right=2;
+int Turn_left=0;
+int Speed1=10; //Half power
+int Speed2=20; //Full power
+int PW_Period=20;
+
+int main()
+{
+ Simplifier::accelerator();
+ VL53Simplifier::runVL53();
+ // default main
+ Drive_pin_D.period_ms(PW_Period);
+ Drive_pin_D.pulsewidth_ms(0);
+ Drive_pin_C.period_ms(PW_Period);
+ Drive_pin_C.pulsewidth_ms(0); //drive motor off
+
+ wait_us(7);
+
+ Drive_pin_A.period_ms(PW_Period); //Steering Servo period
+ Drive_pin_A.pulsewidth_us(1525); //Steering neutral (includes a 25uS offset)
+
+ wait_us(1);
+
+ Drive_pin_D.period_ms(PW_Period);
+ Drive_pin_D.pulsewidth_ms(0);
+ Drive_pin_C.period_ms(PW_Period);
+ Drive_pin_C.pulsewidth_ms(Speed1); //drive motor on forward half power
+
+ wait_us(4);
+ Shape::oval();
+
+ Drive_pin_A.pulsewidth_us(1275); //Half turn right
+
+ wait_us(7 );
+
+ Drive_pin_A.pulsewidth_us(1000); // Full steering lock
+ Drive_pin_C.period_ms(PW_Period);
+ Drive_pin_C.pulsewidth_ms(Speed2); // Full power
+
+ wait_us(5);
+
+ Drive_pin_A.pulsewidth_us(1525); // Neutral steering
+
+ wait_us(1);
+
+ Drive_pin_A.pulsewidth_us(2000); // full steering opposite lock
+
+ wait_us(5.5);
+
+ Drive_pin_A.pulsewidth_us(1525); // Neutral steering
+
+ wait_us(1);
+
+ Drive_pin_D.period_ms(PW_Period); //drive motor reverse
+ Drive_pin_D.pulsewidth_ms(Speed1);
+ Drive_pin_C.period_ms(PW_Period);
+ Drive_pin_C.pulsewidth_ms(0);
+
+ wait_us(3);
+
+ Drive_pin_C.period_ms(PW_Period); //drive motor off
+ Drive_pin_C.pulsewidth_ms(0);
+ Drive_pin_D.period_ms(PW_Period);
+ Drive_pin_D.pulsewidth_ms(0);
+
+}
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Mar 10 08:40:14 2022 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
Binary file resources/official_armmbed_example_badge.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vl53l0x_api.lib Thu Mar 10 08:40:14 2022 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/mjarvisal/code/vl53l0x_api/#e6fcdb78a136