I have motor programmed with arduino, the hardware is already setup so i don't want to change the micro controller. I need to give the motor 1 second to move from each point to the other and if its too much stay until "one second" is done and then go the rest of the code.
the bellow code this is part of the whole code. it freezes and not working after about 40 hour. please advise how can i prevent that. I know that the mills() function is the problem but don't know whats the best option to replace or prevent that?
unsigned long firsttime = 0;
unsigned long secondtime = 0;
void loop(){
...
firsttime= millis();
myStepper.step(RNum);
secondtime = 1000-millis()+firsttime;
delay (secondtime);
...
}
Thanks
I am having Matrice 210 and use OSDK for uploading mission. But the OSDK will not allow uploading if the HomePoint of the aircraft was not initialized.
I got error "WAYPOINT_MISSION_POINTS_TOO_FAR" if turning on the drone only, and I have to turn on RC and connect DJI GO application for the HomePoint being created.
If I understand correctly, the mission manager only accept mission when the drone has strong GPS signal, but the document do not say anything about the HomePoint initializing.
I try to find in the SDK a function to tell the drone get it current GPS as HomePoint, but there is no such thing available in the code. Do I miss something?
Update:
Here is how I setup the mission manager:
void setWaypointInitDefaults(WayPointInitSettings* fdata)
{
fdata->maxVelocity = 10;
fdata->idleVelocity = 5;
fdata->finishAction = 0;
fdata->executiveTimes = 1;
fdata->yawMode = 0;
fdata->traceMode = 0;
fdata->RCLostAction = 1;
fdata->gimbalPitch = 0;
fdata->latitude = 0;
fdata->longitude = 0;
fdata->altitude = 0;
}
...
bool InitWaypointMission(Vehicle* vehicle, int numberWaypoints, double maxSpeed, double turnSpeed, bool usePointsHeading)
{
WayPointInitSettings fdata;
setWaypointInitDefaults(&fdata);
fdata.indexNumber = numberWaypoints;
fdata.maxVelocity = maxSpeed;
fdata.idleVelocity = turnSpeed;
if ( usePointsHeading )
fdata.yawMode = 3;
ACK::ErrorCode initAck = vehicle->missionManager->init(DJI_MISSION_TYPE::WAYPOINT, responseTimeout, &fdata);
if (ACK::getError(initAck))
{
ACK::getErrorCodeMessage(initAck, __func__);
return false;
}
vehicle->missionManager->printInfo();
return true;
}
On DJI drones, the Homepoint is automatically acquired when the drone has visibility of enough GPS satellites. A method that can tell the drone to get its' current position as homepoint will not be useful - if the drone can indeed get a good fix on its' current location in GPS co-ordinates, it has already set it as a homepoint, or will do so in the next few seconds.
There may be many reasons why you are getting the WAYPOINT_MISSION_POINTS_TOO_FAR error, but you will need to provide more context to help us narrow it down. Some things that are useful to report:
After powering on the drone, how long are you letting it sit in clear
skies before trying to upload the mission?
When you initialize your waypoint mission through the MissionManager, have you made sure to set the RCLostAction to Keep Going?
Is the behavior reproducible in simulation?
I am new to Arduino, and right now I am trying to generate a frequency that gradually decreases (without using the tone library) in a program that gradually increases the delay between the switching of the high and low. I have the arduino connected to an audio amp and a speaker.
For some reason, the speaker only outputs a single tone and I dont know why. Here is the code:
void setup()
{
pinMode(3, OUTPUT);
}
void loop()
{
for (int i=100; i <= 25500; i+100){
digitalWrite(3, HIGH);
delayMicroseconds(i);
digitalWrite(3, LOW);
delayMicroseconds(i);
}
}
Any help would be appreciated. I would prefer to try and do this the way I am doing, as opposed to using a completly different method or the tone library.
There is an error in the for statement: the increment statement is actually not a statement. You need to assign i to the new value, i.e. write i = i + 100 instead of just i + 100.
I need a help in arduino uno r3 with push button. By using the registers without using the pinMode, digitalWrite, digitalRead if-else, and switch-case.
int led1=2, led2=3, led3=4, led4=5;
int led5=8, led6=9, led7=10, led8=11;
int button=12;
int i,j,k;
void setup() {
DDRB=DDRB|B00001111;
DDRD=DDRD|B00111100;
Serial.begin (9600);
}
void loop() {
int f=0;
for(int s=0;s<16;s++){
int k=0;
int i=0b00001;
int j=0b0011;
PORTB=f;
f +=1;
if (f==64){f=0;}
PORTD=0;
for(k=0;k<7;k++){
delay(250);
PORTD=i;
delay(250);
PORTD=j;
i=(i<<1);
j=(j<<1);
}
j=(j>>1);
for(int d=0; d<9; d++){
delay(250);
PORTD=i;
delay(250);
PORTD=j;
i=(i>>1);
j=(j>>1);
}
}
}
This is the code. That what I need is to make a while loop for the push button. When I will push the button the program will be start and when I push the button again program will stop.
Well, you can do this in 2 way.
First one
The simple one is writing and reading a byte directly into/fom eeprom. Everytime you press the push button, you need to read it first and validate this value. Lets supose your byte means 0 to turned off and 1 to turned on. So if you push the button and the already saved byte is 0, so you need to change this to 1.
You are going to write using this:
https://www.arduino.cc/en/Tutorial/EEPROMWrite
After this management, you will need to read this byte constantly inside your loop statement. If byte is 1, so your thread can be executed.
You are going to read using this: https://www.arduino.cc/en/Tutorial/EEPROMRead
Second
This is a cannon to kill a mosquito, but can be reused later to manage other kinds of informations. You are going to use the same logic, but saving more detailed or complex values. We are talking about some kind of database.
http://playground.arduino.cc/Code/DatabaseLibrary
I'm sorry but I can't write to you a sample code right now. Job first. If you can't do this untill the end of the day, maybe I can come later and comlete this post to help you out.
I'm attempting to port an old open-source FMOD 3 game (Candy Crisis) to the latest version of FMOD Ex 4 on OS X. Its sound needs are very simpleāit plays WAVs, sometimes changing their frequency or speaker mix, and also plays MOD tracker music, sometimes changing the speed. I'm finding that the game works fine at first, but over the course of a few minutes, it starts truncating sounds early, then the music loses channels and eventually stops, then over time all sound ceases. I can cause the problem to reproduce more quickly if I lower the number of channels available to FMOD.
I can get the truncated/missing sounds issue to occur even if I never play a music file, but music definitely seems to make things worse. I have also tried commenting out the code which adjusts the sound frequency and speaker mix, and that was not the issue.
I am calling update() every frame.
Here's the entirety of my interactions with FMOD to play WAVs:
void InitSound( void )
{
FMOD_RESULT result = FMOD::System_Create(&g_fmod);
FMOD_ERRCHECK(result);
unsigned int version;
result = g_fmod->getVersion(&version);
FMOD_ERRCHECK(result);
if (version < FMOD_VERSION)
{
printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
abort();
}
result = g_fmod->init(8 /* was originally 64, but 8 repros the issue faster */, FMOD_INIT_NORMAL, 0);
FMOD_ERRCHECK(result);
for (int index=0; index<kNumSounds; index++)
{
result = g_fmod->createSound(QuickResourceName("snd", index+128, ".wav"), FMOD_DEFAULT, 0, &s_sound[index]);
FMOD_ERRCHECK(result);
}
}
void PlayMono( short which )
{
if (soundOn)
{
FMOD_RESULT result = g_fmod->playSound(FMOD_CHANNEL_FREE, s_sound[which], false, NULL);
FMOD_ERRCHECK(result);
}
}
void PlayStereoFrequency( short player, short which, short freq )
{
if (soundOn)
{
FMOD::Channel* channel = NULL;
FMOD_RESULT result = g_fmod->playSound(FMOD_CHANNEL_FREE, s_sound[which], true, &channel);
FMOD_ERRCHECK(result);
result = channel->setSpeakerMix(player, 1.0f - player, 0, 0, 0, 0, 0, 0);
FMOD_ERRCHECK(result);
float channelFrequency;
result = s_sound[which]->getDefaults(&channelFrequency, NULL, NULL, NULL);
FMOD_ERRCHECK(result);
result = channel->setFrequency((channelFrequency * (16 + freq)) / 16);
FMOD_ERRCHECK(result);
result = channel->setPaused(false);
FMOD_ERRCHECK(result);
}
}
void UpdateSound()
{
g_fmod->update();
}
And here's how I play MODs.
void ChooseMusic( short which )
{
if( musicSelection >= 0 && musicSelection <= k_songs )
{
s_musicChannel->stop();
s_musicChannel = NULL;
s_musicModule->release();
s_musicModule = NULL;
musicSelection = -1;
}
if (which >= 0 && which <= k_songs)
{
FMOD_RESULT result = g_fmod->createSound(QuickResourceName("mod", which+128, ""), FMOD_DEFAULT, 0, &s_musicModule);
FMOD_ERRCHECK(result);
result = g_fmod->playSound(FMOD_CHANNEL_FREE, s_musicModule, true, &s_musicChannel);
FMOD_ERRCHECK(result);
EnableMusic(musicOn);
s_musicModule->setLoopCount(-1);
s_musicChannel->setPaused(false);
musicSelection = which;
s_musicPaused = 0;
}
}
If someone wants to experiment with this, let me know and I'll upload the project somewhere. My gut feeling is that FMOD is busted but I'd love to be proven wrong.
Sounds like your music needs to be set as higher priority than your other sounds. Remember, lower numbers are more important. I think you can just set the priority on the channel.
Every time I play the following WAV, FMOD loses one channel permanently. I am able to reproduce this channel-losing behavior in the "playsound" example if I replace the existing jaguar.wav with my file.
https://drive.google.com/file/d/0B1eDRY8sV_a9SXMyNktXbWZOYWs/view?usp=sharing
I contacted Firelight and got this response. Apparently WAVs can include a looping command! I had no idea.
Hello John,
I've taken a look at the two files you have provided. Both files end
with a 2 sample infinite loop region.
FMOD 4 (and FMOD 5 for that matter) will see the loop region in the
file and automatically enable FMOD_LOOP_NORMAL if you haven't
specified any loop mode. Assuming you want one-shot behavior just pass
in FMOD_LOOP_OFF when you create the sound.
Kind regards, Mathew Block | Senior Platform Engineer
Technically this behavior contradicts the documented behavior of FMOD_DEFAULT (which is specified to imply FMOD_LOOP_OFF) so they are planning to improve the documentation here.
Based on the wave sample you supplied, FMOD is behaving correctly as it appears you've figured out. The sample has a loop that is honored by FMOD and the last samples are simply repeated forever. While useless, this is correct and the variance in the samples is so slight as to not be audible. While not part of the original spec for wave format, extended information was added later to support meta data such as author, title, comments and multiple loop points.
Your best bet is to examine all your source assets for those that contain loop information. Simply playing all sounds without loop information is probably not the best workaround. Some loops may be intentional. Those that are will have code that stops them. Typically, in a game, the entire waveform is looped when looping is desired. You can then write or use a tool that will strip the loop information. If you do write your own tool, I'd recommend resampling the audio to the native output sampling rate of the hardware. You'd need to insure your resampler was sample accurate (no time shift) and did not introduce noise.
Historically, some game systems had a section at the end of the sound with silence and a loop point set on this region. The short reason for this was to reduce popping that might occur at the end of a sound in a hardware audio channel.
Curiosly, the last 16 samples of your .wav look like garbage and I'm wondering if the .wav assets you're using were converted from a source meant for a game console and that's where the bogus loop information came from as well.
This would have been a comment but my lowly rep does not allow it.