Commit 4f0b7483 authored by Arnaud Blanchard's avatar Arnaud Blanchard

First file for drinving pinobo

parents
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security.
# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
cmake_minimum_required(VERSION 2.6)
project(raspinobo)
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
add_definitions(${BL_DEFINITIONS} -std=c++14 -Wall -W -fdiagnostics-color=always -march=native)
include_directories(${BL_INCLUDE_DIRS})
add_executable(raspinobo raspinobo.cpp bl_raspi.cpp)
target_link_libraries(raspinobo ${BL_LIBRARIES})
if (NOT APPLE)
#Give the raw capbility to the target /dev/mem
add_custom_command(TARGET raspinobo POST_BUILD COMMAND sudo setcap "cap_dac_override+ep cap_sys_rawio+ep cap_sys_nice=eip" $<TARGET_FILE:raspinobo>)
endif()
This diff is collapsed.
#ifndef BL_RASPI_H
#define BL_RASPI_H
#include <stdint.h>
extern uint32_t *bl_raspi_RC_inputs;
extern uint32_t const *bl_raspi_volt_outputs;
extern int bl_raspi_RC_inputs_nb;
extern int bl_raspi_volt_outputs_nb;
/** Number of iterations of the loop. Useful to check the rate of the refreshing loop */
extern int bl_raspi_iterations_nb;
void bl_raspi_add_RC_input(int pin, int us_tau, char const *filename);
void bl_raspi_add_voltage_output(int pin, char const *filename, char const* filename_input);
void bl_raspi_start_loop(uint32_t *RC_results, uint32_t const* voltage_commands);
void bl_raspi_stop_loop();
#endif
#include <sys/ioctl.h> //ioctl
#include <unistd.h> //read getpid
#include <libgen.h> //basename
#include <string.h>
#include <pthread.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <chrono>
#include <thread>
#include "blc_program.h"
#include "blc_channel.h"
#include "bl_raspi.h"
static const int LEFT_POT_PIN=6;
static const int RIGHT_POT_PIN=12;
static const int LEFT_MOTOR_PIN=26;
static const int RIGHT_MOTOR_PIN=20;
blc_channel motor_channel, sensor_channel;
using namespace std;
int main(int argc, char **argv){
char const *gpio_channel_name, *period_str, *default_output, *volts_channel_name;
int us_period, previous_iterations_nb;
char const *values_debug;
char const *commandFile = "command.bin";
char const *currentFile = "current.bin";
char const *forceFile = "force_file.bin";
volts_channel_name="/toto";
SYSTEM_ERROR_CHECK(asprintf((char**)&default_output, "/%s%d", basename(argv[0]), getpid()), -1, "Generating default name"); //This will not be free but it is only allocate once
blc_program_set_description("Pinobo");
blc_program_add_option(&values_debug, 'd', "debug", NULL, "Crete a blc_channel '/o_raspi_gpio_values' too set the sent values", NULL);
blc_program_add_option(&period_str, 'p', "period", "integer", "refresh period in us", "10000"); //100Hz
blc_program_add_option(&gpio_channel_name, 'o', "output", "blc_channel-out", "Channel containing the values of the gpio.", default_output);
// blc_program_add_parameter(&target_channel_name, "blc_channel-in", 1, "Channel defining the volts", NULL );
// blc_program_add_parameter(&volts_channel_name, "blc_channel-in", 1, "Channel defining the volts", NULL );
blc_program_init(&argc, &argv, blc_quit);
SSCANF(1, period_str, "%d", &us_period);
if (gpio_channel_name==NULL) EXIT_ON_ERROR("The ouput channel (option -o) must not be null");
if (volts_channel_name) motor_channel.create_or_open(volts_channel_name, BLC_CHANNEL_WRITE, 'UI32', 'NDEF', 1, 2);
// target_channel.create_or_open(target_channel_name, BLC_CHANNEL_WRITE, 'FL32', 'NDEF', 1, 1);
bl_raspi_add_RC_input(LEFT_POT_PIN, 333, "left_pot_file.bin");
bl_raspi_add_RC_input(RIGHT_POT_PIN, 333, "right_pot_file.bin");
bl_raspi_add_voltage_output(LEFT_MOTOR_PIN, NULL, NULL);
bl_raspi_add_voltage_output(RIGHT_MOTOR_PIN, NULL, NULL);
sensor_channel.create_or_open(gpio_channel_name, BLC_CHANNEL_WRITE, 'UI32', 'NDEF', 1, bl_raspi_RC_inputs_nb);
sensor_channel.publish();
motor_channel.uints32[0]=0;
motor_channel.uints32[1]=0;
bl_raspi_start_loop(sensor_channel.uints32, motor_channel.uints32);
previous_iterations_nb=bl_raspi_iterations_nb;
BLC_COMMAND_LOOP(us_period){
if (blc_loop_iteration!=0) blc_eprint_cursor_up(1);
fprintf(stderr, "Freq:%fHz\n", (bl_raspi_iterations_nb-previous_iterations_nb)/((float)us_period/1000000.f));
previous_iterations_nb=bl_raspi_iterations_nb;
}
bl_raspi_stop_loop();
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment