-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified: include/sensors.h modified: include/types.h new file: include/utils.h modified: include/vehicle.h modified: src/main.c modified: src/sensors.c new file: src/utils.c modified: src/vehicle.c
- Loading branch information
Showing
9 changed files
with
176 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef UTILS_H | ||
#define UTILS_H value | ||
|
||
/*RESOLUTION CONSTANTS*/ | ||
#define W 640 | ||
#define H 480 | ||
/*BITS FOR COLORS*/ | ||
#define N_COL 8 | ||
|
||
void initGridMap(const char n_blocks); | ||
/* Inits grid map | ||
*/ | ||
|
||
void initRandomMap(const int street_w, const int numRoads); | ||
/* Inits a random map, calls initGrid and fills some blocks | ||
*/ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,65 @@ | ||
#include <allegro.h> | ||
#include <math.h> | ||
#include "sensors.h" | ||
#include "types.h" | ||
|
||
void *getFrame(vehicle_t *myVehicle); | ||
void *getRangefinder(vehicle_t *myVehicle); | ||
void initCam(cam_t *myCam) { | ||
myCam->resH = HRES; | ||
myCam->resV = VRES; | ||
} | ||
|
||
void *getFrame(vehicle_t *myVehicle) { | ||
/* provides periodically frames acquired by camera: 33 ms | ||
* code: | ||
*/ | ||
// Camera global position | ||
unsigned x0 = myVehicle->camera.x; | ||
unsigned y0 = myVehicle->camera.y; | ||
|
||
// Camera res a local variable | ||
unsigned hRes = myVehicle->camera.resH; | ||
unsigned vRes = myVehicle->camera.resV; | ||
|
||
// Taking picture | ||
unsigned i, j; | ||
unsigned x, y; | ||
for (i = 0; i < hRes; ++i) { | ||
for(j = 0; j < vRes; j++) { | ||
x = x0 - hRes/2 + i; | ||
y = y0 - vRes/2 + j; | ||
myVehicle->camera.image[i][j] = getpixel(screen, x, y); | ||
} | ||
} | ||
|
||
} | ||
|
||
#define SMIN 10 | ||
#define SMAX 100 | ||
#define STEP 1 | ||
|
||
void *getRangefinder(vehicle_t *myVehicle) { | ||
/* function to provide periodically informations acquired | ||
* by the distance sensor. Period: 20 ms | ||
* code: | ||
*/ | ||
int c; | ||
int x, y; | ||
int d = SMIN; | ||
int x0 = myVehicle->xr; | ||
int y0 = myVehicle->yr; | ||
|
||
double alpha = myVehicle->orientation; | ||
|
||
do { | ||
x = x0 + d * cos(alpha); | ||
y = y0 + d * cos(alpha); | ||
c = getpixel(screen, x, y); | ||
d = d + STEP; | ||
} while ((d <= SMAX) && (c == 8)); | ||
} | ||
|
||
void analyzeCameraFrame(vehicle_t *myVehicle) { | ||
/* Analyzes the camera frame looking for a traffic light | ||
* code: | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <allegro.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
#include "utils.h" | ||
|
||
void initGridMap(const char n_blocks){ | ||
char n_blocks_x, n_blocks_y; | ||
int i, j; | ||
|
||
int block_w = 40; | ||
int street_w = 20; | ||
int someCoeff = block_w + street_w; | ||
|
||
n_blocks_x = W / (2 * n_blocks); | ||
n_blocks_y = H / (2 * n_blocks); | ||
|
||
for(i = 0; i < n_blocks_x; i++){ | ||
for(j = 0; j < n_blocks_y; j++){ | ||
// rectfill(screen, (i * 20 + 5), (j * 15 + 10), | ||
// (i * 15 + 5), (j * 20 + 10), 10); | ||
// rectfill(screen, (j * 20), (i * 20), | ||
// (j * 20 + block_w), | ||
// (i * 20 + block_w), 10); | ||
rectfill(screen, (j * someCoeff), (i * someCoeff), | ||
(j * someCoeff + block_w), | ||
(i * someCoeff + block_w), 10); | ||
} | ||
} | ||
// street_w = 20(j+1) - (20j + block_w) = 20j + 20 - 20j - block_w | ||
// street_w = 20 - block_w; | ||
// street_w + block_w = 20 = someCoeff; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters