-
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.
- Loading branch information
Showing
7 changed files
with
256 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
*.o | ||
*.pyc | ||
rpm_meter_test | ||
test_wavegen | ||
spaxxpos |
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 @@ | ||
gcc -std=gnu99 test_wavegen.c -o test_wavegen -lpigpio -lrt |
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,44 @@ | ||
import serial | ||
import ConfigParser | ||
import time | ||
import os | ||
import sys | ||
import struct | ||
import poslib | ||
from poslib import LinearPositionComm | ||
import threading | ||
|
||
myfolder = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
configfile = os.path.join(myfolder,"..","dro.ini") | ||
os.chdir(myfolder) | ||
print "Reading config file %s"%configfile | ||
config = ConfigParser.ConfigParser() | ||
config.read(configfile) | ||
|
||
port, baudrate , rpm_meter_pin = None, None, None | ||
try: | ||
port = config.get('GENERAL', 'comport') | ||
baudrate = config.get('GENERAL', 'baudrate') | ||
rpm_meter_pin = int(config.get('GENERAL', 'rpm_sensor_pin')) | ||
except Exception, e: | ||
print "Invalid config file: %s"%(str(e)) | ||
exit(1) | ||
|
||
#time.sleep(2) | ||
|
||
#time.sleep(2) #not working after the DLL init_commm has been called. Interference with the signal handler? | ||
try: | ||
with LinearPositionComm(port, baudrate, rpm_meter_pin) as comm: | ||
for i in range(1,1000): | ||
#print "X%.3f "%comm.pos_receiver_lib.get_x_pos() | ||
#print "Y%.3f "%comm.pos_receiver_lib.get_y_pos() | ||
rpm = comm.pos_receiver_lib.get_rpm() | ||
j=0 | ||
while(j < 1000): | ||
j+=1 | ||
sys.stdout.write("RPM %i \r"%(rpm)) | ||
except Exception , e: | ||
print "Exception in the LinearPositionComm: %s"%str(e) | ||
|
||
|
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,181 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
#include <pigpio.h> | ||
#include <time.h> | ||
#include <sys/ioctl.h> | ||
#include <signal.h> | ||
|
||
int gpio=21; | ||
|
||
#define DUR_OFF 10 | ||
#define RAMP_STEP 1 //each pulse during the ramp up period will be shorter by this value | ||
|
||
int start_wave(int on); | ||
|
||
/* | ||
int rampup_wave(int duration){ | ||
printf("Rampup to %i", duration); | ||
// gpioWaveClear(); | ||
int ramp_up = 1000; | ||
char wid[10*ramp_up/RAMP_STEP]; | ||
int wave_no = 0; | ||
while (ramp_up > duration) { | ||
gpioPulse_t pulse[2]; | ||
pulse[0].gpioOn = (1<<gpio); | ||
pulse[0].gpioOff = 0; | ||
pulse[0].usDelay = ramp_up; | ||
pulse[1].gpioOn = 0; | ||
pulse[1].gpioOff = (1<<gpio); | ||
pulse[1].usDelay = DUR_OFF; | ||
gpioWaveAddGeneric(2, pulse); | ||
int wave_id = gpioWaveCreate(); | ||
if (wave_id > 100){ | ||
//too many waves, need to start sending them | ||
//fprintf(stderr, "Will send a set of %i \n", wave_no); | ||
gpioWaveChain(wid, wave_no); | ||
while (gpioWaveTxBusy()) time_sleep(0.001); | ||
for (int i=0; i<wave_no; i++) gpioWaveDelete(wid[i]); | ||
wave_no = 0; | ||
}else { | ||
wid[wave_no] = wave_id; | ||
ramp_up -= RAMP_STEP; | ||
wave_no+=1; | ||
} | ||
//fprintf(stderr, "add wave dur %i ", ramp_up); | ||
//fflush(stderr); | ||
} | ||
//gpioWaveTxSend(wave_id, PI_WAVE_MODE_ONE_SHOT_SYNC); | ||
gpioWaveChain(wid, wave_no); | ||
while (gpioWaveTxBusy()) time_sleep(0.001); | ||
start_wave(duration); | ||
for (int i=0; i<wave_no; i++) gpioWaveDelete(wid[i]); | ||
return 0; | ||
} | ||
*/ | ||
|
||
int rampup_wave(int duration){ | ||
printf("Rampup to %i", duration); | ||
// gpioWaveClear(); | ||
|
||
int ramp_up = 1000; | ||
|
||
int wave_no = 0; | ||
while (ramp_up > duration) { | ||
|
||
#define NO_OF_PULSES_PER_RAMPSTEP 10 | ||
gpioPulse_t pulse[NO_OF_PULSES_PER_RAMPSTEP*2]; | ||
for (int i= 0; i < 2*NO_OF_PULSES_PER_RAMPSTEP-1; i++){ | ||
pulse[i].gpioOn = (1<<gpio); | ||
pulse[i].gpioOff = 0; | ||
pulse[i].usDelay = ramp_up; | ||
|
||
pulse[i+1].gpioOn = 0; | ||
pulse[i+1].gpioOff = (1<<gpio); | ||
pulse[i+1].usDelay = ramp_up; | ||
} | ||
gpioWaveAddGeneric(NO_OF_PULSES_PER_RAMPSTEP*2, pulse); | ||
int wave_id = gpioWaveCreate(); | ||
gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT_SYNC); | ||
//while (gpioWaveTxBusy()) time_sleep(0.01); | ||
//time_sleep(0.01); | ||
gpioWaveDelete(wave_id); | ||
ramp_up -= RAMP_STEP; | ||
//fprintf(stderr, "add wave dur %i ", ramp_up); | ||
//fflush(stderr); | ||
} | ||
//gpioWaveTxSend(wave_id, PI_WAVE_MODE_ONE_SHOT_SYNC); | ||
//gpioWaveChain(wid, wave_no); | ||
//while (gpioWaveTxBusy()) time_sleep(0.0001); | ||
start_wave(duration); | ||
//for (int i=0; i<wave_no; i++) gpioWaveDelete(wid[i]); | ||
return 0; | ||
} | ||
|
||
int start_wave(int on){ | ||
//gpioWaveClear(); | ||
//fprintf(stderr, "start wave %i ", on); | ||
//fflush(stderr); | ||
// gpioWaveClear(); | ||
|
||
gpioPulse_t pulse[2]; | ||
pulse[0].gpioOn = (1<<gpio); | ||
pulse[0].gpioOff = 0; | ||
pulse[0].usDelay = on; | ||
|
||
pulse[1].gpioOn = 0; | ||
pulse[1].gpioOff = (1<<gpio); | ||
pulse[1].usDelay = on; | ||
|
||
gpioWaveAddGeneric(2, pulse); | ||
int wave_id = gpioWaveCreate(); | ||
if (wave_id < 0){ | ||
fprintf(stderr, "Wave create error\n"); | ||
if (wave_id == PI_EMPTY_WAVEFORM){ | ||
fprintf(stderr, "PI_EMPTY_WAVEFORM\n"); | ||
}else if (wave_id == PI_TOO_MANY_CBS){ | ||
fprintf(stderr, "PI_TOO_MANY_CBS\n"); | ||
}else if (wave_id == PI_TOO_MANY_OOL){ | ||
fprintf(stderr, "PI_TOO_MANY_OOL\n"); | ||
}else if (wave_id == PI_NO_WAVEFORM_ID){ | ||
fprintf(stderr, "PI_NO_WAVEFORM_ID\n"); | ||
}; | ||
|
||
return 1; | ||
} | ||
|
||
gpioWaveTxSend(wave_id, PI_WAVE_MODE_REPEAT_SYNC); | ||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int on=1000; | ||
|
||
if (argc > 3) | ||
{ | ||
gpioInitialise(); | ||
gpioWaveClear(); | ||
fprintf(stderr, "Too many params"); | ||
return 1; | ||
} | ||
else if (argc > 2) | ||
{ | ||
on = atoi(argv[2]); | ||
gpio = atoi(argv[1]); | ||
} | ||
else if (argc > 1) | ||
{ | ||
gpio = atoi(argv[1]); | ||
} | ||
|
||
printf("gpio=%d on=%d\n", gpio, on); | ||
|
||
if (gpioInitialise()<0) return -1; | ||
|
||
gpioSetMode(gpio, PI_OUTPUT); | ||
|
||
rampup_wave(on); | ||
|
||
//start_wave(on); | ||
while (1) { | ||
int var = getchar(); | ||
if(var == 's') break; | ||
if(var == '+') { | ||
on += 1; | ||
start_wave(on); | ||
} | ||
if(var == '-') { | ||
on -= 1; | ||
start_wave(on); | ||
} | ||
time_sleep(0.01); | ||
} | ||
gpioWaveClear(); | ||
gpioTerminate(); | ||
} |