/****************************************************************************
*
* Copyright (c) 2012-2016 PX4 Development Team. All rights reserved.
* Copyright 2019 NXP.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file hg_led.c
* Minimal application for led control
*
* @author Leutrim Mustafa
*/#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/posix.h>
#include <unistd.h>
#include <stdio.h>
#include <poll.h>
#include <string.h>
#include <uORB/uORB.h> // asynchronous messaging API used for inter-thread/inter-process communication
#include <uORB/topics/led_control.h> // uORB for led_control__EXPORT int hg_led_main(int argc, char *argv[]); // Export main for starting in another thread
int hg_led_main(int argc, char *argv[])
{
PX4_INFO("Hello Hovergames LED"); // Create structure to store data in
struct led_control_s led_control;
// Clear the structure by filling it with 0s in memory
memset(&led_control, 0, sizeof(led_control));
// Create a uORB topic advertisement
orb_advert_t led_control_pub = orb_advertise(ORB_ID(led_control), &led_control); led_control.num_blinks = 10; // Blink 10 times
led_control.priority = LED_CONTROL_MAX_PRIORITY; // Set our app to max priority
led_control.mode = LED_CONTROL_MODE_BLINK_NORMAL; // Set the LED mode to blink
led_control.led_mask = 0xff; // Select all LEDs
led_control.color = LED_CONTROL_COLOR_GREEN; // Set color to green orb_publish(ORB_ID(led_control), led_control_pub, &led_control); PX4_INFO("Hovergames LED exit");
return 0; // return of main function
}vehicle_local_posititonpx4_add_module(
MODULE examples__hg_led
MAIN hg_led
STACK_MAIN 2000
SRCS
hg_led.c
DEPENDS
) EXAMPLES
fixedwing_control # Tutorial code from https://px4.io/dev/example_fixedwing_control
hello
hg_led # Our example application!
hwtest # Hardware test
#matlab_csv_serial
px4_mavlink_debug # Tutorial code from http://dev.px4.io/en/debug/debug_values.html
px4_simple_app # Tutorial code from http://dev.px4.io/en/apps/hello_sky.html
rover_steering_control # Rover example app
uuv_example_app
work_item
LINK to file: https://github.com/PX4/Firmware/blob/master/msg/sensor_gyro.msg
-----------------------------------------------------------------------------
uint64 timestamp # time since system start (microseconds)
uint64 timestamp_sample
uint32 device_id # unique device ID for the sensor that does not change between power cycles
float32 x # angular velocity in the NED X board axis in rad/s
float32 y # angular velocity in the NED Y board axis in rad/s
float32 z # angular velocity in the NED Z board axis in rad/s
float32 temperature # temperature in degrees celsius
uint32 error_count
uint8 ORB_QUEUE_LENGTH = 8/****************************************************************************
*
* Copyright (c) 2012-2016 PX4 Development Team. All rights reserved.
* Copyright 2019 NXP.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file hg_gyro.c
* Minimal application reading gyro values from uORB service
*
* @author Leutrim Mustafa
*/// px4_config and posix are needed for just about every PX4 user application.
#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/posix.h>
// These are basic headers that will be needed for polling messages,
// manipulting strings, standart input/output, and POSIX compliance.
#include <unistd.h>
#include <stdio.h>
#include <poll.h>
#include <string.h>
// These headers are for the uORB messaging system. We include the base uORB
// header and a header for the topic we will be using (sensor_gyro!)
#include <uORB/uORB.h>
#include <uORB/topics/sensor_gyro.h>// Export main function so that we can call on it in PX4
__EXPORT int hg_gyro_main(int argc, char *argv[]);
// Define our main function
int hg_gyro_main(int argc, char *argv[]) {
PX4_INFO("Hello Hovergames gyro!"); // Prints "Hello Hovergames Gyro!" to the console // Subscirbe to "sensor_gyro", then set a polling interval of 200ms
int gyro_sub = orb_subscribe(ORB_ID(sensor_gyro));
orb_set_interval(gyro_sub, 200);
// Configure a POSIX POLLIN system to sleep the current thread until
// data appears on the topic
px4_pollfd_struct_t fds_gyro;
fds_gyro.fd = gyro_sub;
fds_gyro.events = POLLIN; int counter = 20;
printf("%02i | gyro_x | gyro_y | gyro_z\n", counter);
printf("-----------------------------------\n"); // Loop a specified number of times
for(int i = 1; i <= counter; i++)
{
// Allow the POSIX POLLIN system to poll for data, with 1000ms timeout
int poll_ret = px4_poll(&fds_gyro, 1, 1000);
// If px4_poll returns 0, then the poll system timed out! Throw an error.
if(poll_ret == 0)
{
PX4_ERR("Got no data within a second");
}
// If it didn't return 0, we got data!
else
{
// Double check that the data we recieved was in the right format (I think - need to check)
if(fds_gyro.revents & POLLIN)
{
// Create a sensor_gyro_s struct to store the data we recieved
struct sensor_gyro_s gyro;
// Copy the data over to the struct
orb_copy(ORB_ID(sensor_gyro), gyro_sub, &gyro);
// Finally, print the data!
printf("printf("%02i | %+2.2f | %+2.2f | %+2.2f \n", i,
(double)gyro.x, (double)gyro.y, (double)gyro.z);
}
}
}
// Tell the user that the application is ending...
PX4_INFO("Hovergames gyro exit");
// Typical C exit :)
return 0;
}








