Commit 6e124a1b authored by ARnaud Blanchard's avatar ARnaud Blanchard

Nig improvement but not yet working

parent 6c573609
......@@ -22,7 +22,7 @@ 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
#Give the raw capability 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()
......@@ -4,6 +4,15 @@ Setup the raspberry has an access point
More details here in the original tuatorial ( https://github.com/SurferTim/documentation/blob/6bc583965254fa292a470990c40b145f553f6b34/configuration/wireless/access-point.md )
Check the frequency:
`sudo cat /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_cur_freq`
Check temperature:
`/opt/vc/bin/vcgencmd measure_temp`
Video tracking
......
This diff is collapsed.
......@@ -7,11 +7,12 @@ extern uint32_t *bl_raspi_RC_inputs;
extern unsigned char const *bl_raspi_volt_outputs;
extern int bl_raspi_RC_inputs_nb;
extern int bl_raspi_volt_outputs_nb;
extern int buffer_size;
/** Number of iterations of the loop. Useful to check the rate of the refreshing loop */
extern int bl_raspi_iterations_nb;
extern volatile int bl_raspi_iterations_nb;
void bl_raspi_add_RC_input(int pin, int us_tau, char const *filename);
void bl_raspi_add_RC_input(int pin, int us_tau, uint32_t *buffer);
void bl_raspi_add_voltage_output(int pin, char const *filename, char const* filename_input);
void bl_raspi_start_loop(uint32_t *RC_results, unsigned char const* voltage_commands);
......
......@@ -7,14 +7,17 @@
#include <math.h>
#include <iostream>
#include <fstream>
#include <chrono>
#include <thread>
#include <chrono>
#include <time.h>
#include "blc_program.h"
#include "blc_channel.h"
#include "bl_raspi.h"
static const int SOUND_PIN=13;
static const int LEFT_POT_PIN=6;
static const int RIGHT_POT_PIN=12;
static const int LEFT_MOTOR_PIN=26;
......@@ -34,7 +37,7 @@ static uchar gaussian_cdf(uint32_t s, float mu, float var){
blc_channel motor_channel, sensor_channel, neurons_channel;
int main(int argc, char **argv){
blc_channel gain_channel, target_channel;
blc_channel gain_channel, target_channel, buffer_channel;
char const *gpio_channel_name, *period_str, *volts_channel_name, *target_channel_name, *tracking, *gain_name;
int us_period, previous_iterations_nb;
char const *values_debug;
......@@ -62,11 +65,16 @@ int main(int argc, char **argv){
if (gpio_channel_name==NULL) EXIT_ON_ERROR("The ouput channel (option -o) must not be null");
// target_channel.create_or_open(target_channel_name, BLC_CHANNEL_WRITE, 'FL32', 'NDEF', 1, 1);
buffer_size=1024;
buffer_channel.create_or_open("/buffer", BLC_CHANNEL_WRITE, 'UI32', 'NDEF', 1, buffer_size);
bl_raspi_add_RC_input(SOUND_PIN, 1, buffer_channel.uints32);//"left_pot_file.bin")
/*
bl_raspi_add_RC_input(LEFT_POT_PIN, 333, NULL);//"left_pot_file.bin");
bl_raspi_add_RC_input(RIGHT_POT_PIN, 333, NULL); //"right_pot_file.bin");
bl_raspi_add_voltage_output(LEFT_MOTOR_PIN, NULL, NULL);
bl_raspi_add_voltage_output(RIGHT_MOTOR_PIN, NULL, NULL);
bl_raspi_add_voltage_output(RIGHT_MOTOR_PIN, NULL, NULL);*/
motor_channel.create_or_open(volts_channel_name, BLC_CHANNEL_WRITE, 'UIN8', 'NDEF', 1, 2);
sensor_channel.create_or_open(gpio_channel_name, BLC_CHANNEL_WRITE, 'UI32', 'NDEF', 1, bl_raspi_RC_inputs_nb);
......@@ -74,11 +82,12 @@ int main(int argc, char **argv){
neurons_channel.create_or_open("/pinobo.neurons", BLC_CHANNEL_WRITE, 'UIN8', 'NDEF', 1, 3);
target_channel.create_or_open(target_channel_name, BLC_CHANNEL_READ, 'UIN8', 'NDEF', 1, 2);
gain_channel.create_or_open("/pinobo.gain", BLC_CHANNEL_READ, 'UIN8', 'NDEF', 1, 1);
gain_channel.create_or_open("/pinobo.gain", BLC_CHANNEL_READ, 'UIN8', 'NDEF', 1, 1);
motor_channel.uchars[0]=0;
motor_channel.uchars[1]=0;
bl_raspi_start_loop(sensor_channel.uints32, motor_channel.uchars);
previous_iterations_nb=0;
......@@ -109,53 +118,22 @@ int main(int argc, char **argv){
uchar right_motor;
}line;
SYSTEM_ERROR_CHECK(record_file=fopen("pinobo.data", "w"), NULL, "Opening 'pinobo.data'");
chrono::high_resolution_clock::time_point tp = chrono::high_resolution_clock::now();
//SYSTEM_ERROR_CHECK(record_file=fopen("pinobo.data", "w"), NULL, "Opening 'pinobo.data'");
struct timespec timestamp;
uint32_t previous_ns, delay_ns;
previous_ns=0;
BLC_COMMAND_LOOP(us_period){
if (blc_loop_iteration!=0) blc_eprint_cursor_up(1);
FOR(i, 2){
neurons_channel.uchars[i]=neurons[i].update(sensor_channel.uints32[i]);
}
fprintf(stderr, "Freq:%fHz\n n0:%d n0mu:%f n0var:%f", (bl_raspi_iterations_nb-previous_iterations_nb)/((float)us_period/1000000.f), neurons_channel.uchars[2], neurons[0].mu, neurons[0].var);
int tmp=(255-neurons_channel.uchars[1]);
int avg=128+(neurons_channel.uchars[0]-neurons_channel.uchars[1])/2;
int dist_avg=abs(avg-neurons_channel.uchars[2]);
int dist_tmp=abs(tmp-neurons_channel.uchars[2]);
int dist_0=abs(neurons_channel.uchars[0]-neurons_channel.uchars[2]);
if (avg<=dist_tmp){
if (avg<=dist_0) neurons_channel.uchars[2] = avg;
else neurons_channel.uchars[2] = neurons_channel.uchars[0];
}
else if (dist_0 < dist_tmp) neurons_channel.uchars[2] = neurons_channel.uchars[0];
else neurons_channel.uchars[2]=tmp;
clock_gettime(CLOCK_MONOTONIC, &timestamp);
if (timestamp.tv_nsec > previous_ns) delay_ns = timestamp.tv_nsec-previous_ns;
else delay_ns = 1000000000 - previous_ns + timestamp.tv_nsec;
previous_ns=timestamp.tv_nsec;
if (gain_channel.uchars[0]!=0)
{
if (gain_channel.uchars[0]>30) error = (target_channel.uchars[0]-neurons_channel.uchars[2])*gain_channel.uchars[0]/128;
else error = (target_channel.uchars[0]-128)*gain_channel.uchars[0]/128 + error/2;
if ( neurons_channel.uchars[2]==0) error=-20;
else if ( neurons_channel.uchars[2]==255) error=20;
if (abs(error)>1){
motor_channel.uchars[0]+=(CLIP_UCHAR(-error)- motor_channel.uchars[0]);
motor_channel.uchars[1]+=(CLIP_UCHAR(+error)-motor_channel.uchars[1]);
}
else{
motor_channel.uchars[0]=0;
motor_channel.uchars[1]=0;
}
}
line.time=chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now()-tp).count();
line.left_pot=sensor_channel.uints32[0];
line.right_pot=sensor_channel.uints32[1];
line.left_motor=motor_channel.uchars[0];
line.right_motor=motor_channel.uchars[1];
fwrite(&line, sizeof(line), 1, record_file);
fprintf(stderr, "%f, Freq:%fMHz\n n0:%d n0mu:%f n0var:%f", (float)delay_ns, (bl_raspi_iterations_nb-previous_iterations_nb)/((float)(delay_ns/1000)), neurons_channel.uchars[2], neurons[0].mu, neurons[0].var);
previous_iterations_nb=bl_raspi_iterations_nb;
}
......
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